The level editor now allows a map to be saved and loaded.
Began pulling the code out of Resistor for saving game files for my ResistorKit library. Saving files is much more trickier than just opening up a file handle and writing out a string. This was probably the most time consuming task in Resistor that produced the smallest results.
The three file IO methods I’ve included in the ResistorKit are beginLoadGame, saveGame, loadGame, and getLoadData. The beginLoadGame method should probably be renamed, since it just does the processing necessary to get a storage device. This method must be called and complete before the other two methods are used. The saveGame method takes three parameters, which are the container name, file name, and data string. The container name is basically just a folder created in C:Users<username>DocumentsSavedGames on Windows. On the XBox, this is the name of the save on your storage device. The file name is the name of the file to write out in that folder on Windows. On the XBox, the user should never actually be able to see the file name. The loadGame method takes two parameters, which are the container and filename. After the loadGame method is finished, the character string data from the file can be obtained by calling getLoadData.
In my Level Editor screen, I have assigned beginLoad game to the X button, saveGame to the left bumper, and loadGame/getLoadData to the right bumper. When the data is saved, it writes out the array of 1’s and 0’s to the text file. I wrote a method to serialize the data from the array to make this task simpler. When the data is loaded, the text data is stored in a variable which is displayed to the screen. Conversely, I wrote a deserialize method which takes the loaded text data and populates the map array.
I’ve also decided to keep one save file for all players. Saving for a specific profile caused problems with Resistor, so I’ve learned that making one global save file is the much easier approach.
One Reply to “Saving and Loading Maps”
Comments are closed.