所以,我在这里遇到了一个奇怪的问题。我在 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()
级别.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 压缩来压缩图块。“瓷砖/瓷砖”加载得很好,但调用仍然失败,我仍然得到 OutOfMemoryException。我的内容的总文件大小为 1.23 MB。