Time for action – implementing loading and saving

  1. In the Tile Engine project open the TileMap.cs class file.
  2. Add the Loading and Saving Maps region to the TileMap class:
    #region Loading and Saving Maps public static void SaveMap(FileStream fileStream) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(fileStream, mapCells); fileStream.Close(); } public static void LoadMap(FileStream fileStream) { try { BinaryFormatter formatter = new BinaryFormatter(); mapCells =(MapSquare[,])formatter.Deserialze(fileStream); fileStream.Close(); } catch { ClearMap(); } } public static void ClearMap() { for (int x = 0; x < MapWidth; x++) for (int y = 0; y < MapHeight; y++) for (int z = 0; z < MapLayers; z++) { mapCells[x, y] = new MapSquare(2, ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.