因此,我在這裏遇到了一個奇怪的問題。我在Windows,Xbox 360和Windows Phone 7上使用了相同的XNA代碼。我可以使用它的大部分功能,但是當Level試圖在Windows Phone 7版本上調用TileMap時,它永遠不會到達TileMap。但是,在Windows和Xbox 360上,它工作得很好。有什麼額外的,我必須在這裏做?在Windows Phone 7上撥打電話失敗,但在Windows和Xbox 360上工作
更多的細節。在Windows Phone版本中,我收到調試器發出的「無法評估表達式」消息的某些值。這在Windows版本上不會發生。同樣,如果我讓它繼續足夠長的時間,即使我調用的圖像大小約爲KB,並且.map文件只會創建3x3矩陣,我也會得到OutOfMemoryException。
GameplayScreen.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之外的「瓷磚/瓷磚」,我試圖用DXT壓縮來壓縮瓷磚。 「瓷磚/瓷磚」加載完美,但調用仍然失敗,我仍然得到OutOfMemoryException。我的內容的總文件大小是1.23 MB。
我不知道很多關於WP7,而是根據你的描述我不認爲你的紋理大小是傷害你的地方,在這裏。如果在創建TileMap之前調用'GC.GetTotalMemory()',多少內存正在被消耗?內存中的'TileMap'類有多大?發佈更完整版本的'TileMap'可能會有用。 –
在Visual Studio中評估表達式(例如,在「監視」窗口中)時,在此情況下,將在目標平臺上執行該命令(假設它是手機或模擬器)。此表達式評估有一定的超時時間,因此無法按時完成。你是在真實設備上還是在仿真器上嘗試這種方法?也請嘗試運行相同的代碼而不進行調試,看看結果是否相同。 –