gpt4 book ai didi

c# - 在 Windows Phone 7 上通话失败,但在 Windows 和 Xbox 360 上可以正常工作

转载 作者:太空宇宙 更新时间:2023-11-03 16:32:35 25 4
gpt4 key购买 nike

所以,我遇到了一个奇怪的问题。我在 Windows、Xbox 360 和 Windows Phone 7 上使用相同的 XNA 代码。我可以让它的大部分工作,但是当 Level 尝试在 Windows Phone 7 版本上调用 TileMap 时,它永远不会到达 TileMap。但是,在 Windows 和 Xbox 360 上,它工作得很好。有什么我必须在这里做的额外事情吗?

更多细节。在 Windows Phone 版本上,我收到来自调试器的某些值的“无法计算表达式”消息。这不会发生在 Windows 版本上。同样,如果我让它持续足够长的时间,我会得到一个 OutOfMemoryException,即使我调用的图像大小约为 KB,并且 .map 文件只会创建一个 3x3 矩阵。

游戏画面.cs

    private Level level;
...
public override void LoadContent()
{
if (Content == null)
Content = new ContentManager(ScreenManager.Game.Services, "Content");
//Create Sprite Batch for drawing textures
//spriteBatch = new SpriteBatch(GraphicsDevice);

//Load fonts
hudFont = Content.Load<SpriteFont>("Fonts/hud");

lifeIcon = Content.Load<Texture2D>("Sprites/Player/lifeIco");

//Load overlays
//winOverlay = Content.Load<Texture2D>("Overlays/win");
//loseOverlay = Content.Load<Texture2D>("Overlays/lose");

try
{
MediaPlayer.IsRepeating = true;
MediaPlayer.Play(Content.Load<Song>("Sounds/music"));
}
catch { }

LoadNextLevel();

//Camera.InitializeScreen(graphics);

base.LoadContent();
} //end LoadContent

/// <summary>
/// Loads the next level.
/// </summary>
public void LoadNextLevel()
{
//Set the next level
levelIndex = (levelIndex + 1) % numberOfLevels;

if (level != null)
level.Dispose();

level = new Level(ScreenManager.Game.Services, levelIndex);

} //end LoadNextLevel()

Level.cs

    private TileMap levelMap;
public Level(IServiceProvider service, int levelIndex)
{
//Create content manager for current level.
content = new ContentManager(service, "Content");

//Load level map
//This is where the code hangs
levelMap = new TileMap(this, levelIndex, content.Load<Texture2D>(@"Tiles/tiles"));


//Load sounds
//exampleSound = content.Load<SoundEffect>("Sounds/example");

//Initialize Camera
Camera.InitializeLevel(levelMap);
player = new Player(this, start);
} //end Level

TileMap.cs

    public TileMap(Level level, int levelIndex, Texture2D tileSheet)
{
// Never reaches here on Windows Phone 7 Version
// Comes right here on Windows and Xbox 360 Version
this.tileSheet = tileSheet;

string levelPath = string.Format("Content/Levels/{0}.map", levelIndex);

一些我已经被建议并尝试做的事情:

我曾尝试在调用 Tile Map 之外调用“Tiles/tiles”,并尝试使用 DXT 压缩来压缩图 block 。 “Tiles/tiles”加载非常好,但调用仍然失败,我仍然得到 OutOfMemoryException。我的内容的总文件大小为 1.23 MB。

最佳答案

在 Level.cs 中,不是将内容作为服务传递,而是传递预先加载的所有内容:{Texture2D, Sound}。在 XNA 中,您通常会在主游戏类或组件中加载所有内容。我 95% 认为这是“无法计算表达式”的原因。

另外,看看 .NET Compact Framework 2.0 并了解垃圾收集器的工作原理:

http://blogs.msdn.com/b/stevenpr/archive/2004/07/26/197254.aspx

关于c# - 在 Windows Phone 7 上通话失败,但在 Windows 和 Xbox 360 上可以正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10379961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com