2
votes

I am currently writing a 2D game using the XNA Game Studio 4.0 framework for Windows Phone 7. I have gotten to the stage where I am tackling the problem of tomb-stoning the game if the user would like to save/load or if they resume the game at a later point.

I'm currently using the TiledLib library for the rendering etc of the map and also the screen state management example as a basis for my project (eg the events for tombstoning correctly are all in place). The Map object in the TiledLib library has a multidimensional array ([,]) to store the tiles of the map within each TileLayer. My map only has one TileLayer, and only 1 Texture2D with different Rectangle source locations base on what the tile is displaying. It is important that I track all of the appropriate source rectangles for each tile so the map that has been edited can be resumed the way the player left it.

I'm having quite a lot of trouble trying to work out the best way (or any way) to achieve tombstoning for the game screen. I have not had much experience with serialization and this is my first attempt at tombstoning for a Windows Phone 7 application. I understand that non-jagged arrays can not be serialized using the usual XmlSerializer, is there a method to get around this? Is a custom serializer a good path to go down? Pros/Cons? Has any one else had experience with TileLib and serializing a game screen? Or a 2D map with an X,Y coordinates? How much data is too much data to serialize for tombstoning?

Thanks in advance for answers and advice.

1

1 Answers

3
votes

I would recommend writing your own serialization routines using BinaryReader and BinaryWriter, on the basis that you can serialize completely arbitrary data, with full control over the process, and with considerably more speed than automatic XML serialization.

The downside, of course, is that you must keep your read and write routines in sync with one another, and with the classes you are serializing. Also you will need a mechanism for handling changes in your serialization format, if your code changes (you add or remove data to serialize).