Time for action – implementing loading and saving
In the Tile Engine project open the
TileMap.cs
class file.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, 0, 0, "", true); } } #endregion
Back in the Level Editor project, open the MapEditor form in Design mode...