O'Reilly logo

XNA 4.0 Game Development by Example Beginner's Guide by Kurt Jaegers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required