Well, since your Map object somewhat mirrors mine, I can show you what i did to solve the problem.
First I created a tilelist to hold an array of each row.
Then when i went to serialize it, I populated the tilelist and then serialized the list instead of the array. I'm not 100% done with these functions yet so there might be a few bugs left. (Maybe an odd indexOutOfBounds error I havent nailed down yet or something.)
But here is my class. (The reason i made the tilelist is because I'm a lazy programmer and didn't want to have to reprogram a good portion of my project to get this working.... also to keep the simplicity of using a 2D array.)
| public class Map |
| { |
| public Vector2 mapsize |
| { |
| get; |
| set; |
| }//in tiles. |
| |
| public Vector2 tilesize |
| { get; set; }//in pixels; |
| public byte numberOfLayers |
| { get; set; } |
| |
| //[XmlIgnore()] |
| Tile[,] tiles |
| { get; set; } |
| |
| public List<Tile[]> tilelist; |
| |
| |
| |
| //used on saving the map |
| public void createTileList() |
| { |
| tilelist =new List<Tile[]>(); |
| Tile[] tileRow; |
| tileRow = new Tile[(int)mapsize.X]; |
| |
| |
| for (int i = 0; i < (int)mapsize.Y; i++) |
| { |
| tileRow = new Tile[(int)mapsize.X]; |
| for (int j = 0; j < (int)mapsize.X; j++) |
| { |
| tileRow[j] = tiles[j, i]; |
| } |
| tilelist.Add(tileRow); |
| } |
| |
| } |
| |
| //used on loading the map |
| public void serialized() |
| { |
| tiles = new Tile[(int)mapsize.X, (int)mapsize.Y]; |
| Tile[] currentRow; |
| |
| for (int i = 0; i < (int)mapsize.Y; i++) |
| { |
| currentRow = tilelist[i]; |
| for (int j = 0; j < (int)mapsize.X; j++) |
| { |
| tiles[j, i] = currentRow[j]; |
| tiles[j, i].loadTexture(); |
| } |
| } |
| |
| } |
| } |
Hope this helps a bit =)
::EDIT:: Quick note, when i serialize into an XML file, I call createTileList() then i serialize. When loading from an XML file into an Object, i call serialized() after I read into the object. Also, the tile.loadTexture() loads the texture into memory from a fileaddress (so i can use several spritemaps on one map)
-Pandarus