XNA Creators Club Online
Page 1 of 1 (7 items)
Sort Posts: Previous Next

There was an error reflecting type 'TileMapEditor.Map'. When trying to save my tile map.

Last post 12/08/2009 17:08 by Pandarus PurpleSky. 6 replies.
  • 21/05/2009 21:22

    There was an error reflecting type 'TileMapEditor.Map'. When trying to save my tile map.

    Ok i know everyone is probly over joyed with excitment with me posting yet another problem lol.  Now that I have an editor capable of changin tiles texture with the current texture in a list ive decided to try to save it as an XML File.

    heres my large section of source code.

        [Serializable]  
        public class Map  
        {  
            public Tile[,] Tiles;  
            public float[] Horizontal;  
            public float[] Verticle;  
            public int Size;  
        }  
        class TileMap  
        {  
            float[] Horizontal;  
            float[] Verticle;  
            Tile[,] Tiles;  
            int size;  
     
            int PreX, PreY;  
     
            public TileMap(int Size, Texture2D Tex)  
            {  
                size = Size;  
                Horizontal = new float[size];  
                Verticle = new float[size];  
                Tiles = new Tile[size,size];  
     
                for (int i = 0; i < size; i++)  
                {  
                    Horizontal[i] = i * 32;  
                    Verticle[i] = i * 32;  
                }  
                for (int x = 0; x < size; x++)  
                {  
                    for (int y = 0; y < size; y++)  
                    {  
                        Tiles[x, y] = new Tile(Tex);  
                        Tiles[x, y].Postition = new Vector2(Horizontal[x], Verticle[y]);  
                    }  
                }  
            }  
            public void SelectedTile(int x, int y)  
            {  
                if (PreX != x)  
                {  
                    Tiles[PreX, PreY].TileColor = Color.White;  
                }  
                if (PreY != y)  
                {  
                    Tiles[PreX, PreY].TileColor = Color.White;  
                }  
                  
                Tiles[x, y].TileColor = Color.Red;  
                PreX = x;  
                PreY = y;  
            }  
            public int MapSize()  
            {  
                return size;  
            }  
              
            public void UpdateTileTex(Texture2D[] Tex, int x, int y, int ID)  
            {  
                //Tiles[x,y].TileTexture = Tex;  
                Tiles[x,y].UpdateTile(Tex,ID);  
            }  
            public void DrawMap(SpriteBatch SB)  
            {  
                foreach (Tile T in Tiles)  
                {  
                    SB.Draw(T.TileTexture, T.Postition, T.TileColor);  
                }  
            }  
            public void SaveMap(string Path)  
            {  
                Map M = new Map();  
                string blah = Path + "Level.xml";  
                M.Tiles = Tiles;  
                M.Horizontal = Horizontal;  
                M.Verticle = Verticle;  
                M.Size = size;  
                FileStream FS = new FileStream(blah, FileMode.Create);  
                XmlSerializer W = new XmlSerializer(typeof(Map));  
                W.Serialize(FS, M);  
                FS.Close();  
            }  
        } 
    And Heres my Tile class.

        public class Tile  
        {  
            public Texture2D TileTexture;  
            public Vector2 Postition;  
            public Color TileColor = Color.White;  
            public int TileID;  
            public float Layer = 0.0f;  
              
            public Tile(Texture2D T)  
            {  
                TileTexture = T;  
            }  
            public void UpdateTile(Texture2D[] Text, int ID)  
            {  
                TileTexture = Text[ID];  
                TileID = ID;  
            }  
        } 
    For the Horde
  • 21/05/2009 21:33 In reply to

    Re: There was an error reflecting type 'TileMapEditor.Map'. When trying to save my tile map.

    I assume it has something to do with me using 2d arrays.  If so is there a way to get around it? using xml or will i need to use binary readers/ writers
    For the Horde
  • 21/05/2009 22:55 In reply to

    Re: There was an error reflecting type 'TileMapEditor.Map'. When trying to save my tile map.

    Heres an update i converted a 2d array to a large 1d array had to change my tile class but now when i save it causes the program to lock up the xml file was writen to cause it has a size but i cant open the file it causes the IE to close.
    For the Horde
  • 11/08/2009 22:16 In reply to

    Re: There was an error reflecting type 'TileMapEditor.Map'. When trying to save my tile map.

    what error are you getting?
  • 12/08/2009 7:15 In reply to

    Re: There was an error reflecting type 'TileMapEditor.Map'. When trying to save my tile map.

    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  
            { getset; }//in pixels;  
            public byte numberOfLayers  
            { getset; }  
     
            //[XmlIgnore()]  
            Tile[,] tiles  
            { getset; }  
     
            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
    Development Blog: http://gamerrants.blogspot.com
  • 12/08/2009 9:18 In reply to

    Re: There was an error reflecting type 'TileMapEditor.Map'. When trying to save my tile map.

    I don't think serializing a Texture2D is going to do what you want. I have no idea what it'll actually do, but I'm certain it won't be what you intended. :)

    I would tag the TileTexture member of Tile with [XmlIgnore].
    Kevin Gadd, Squared Interactive
    Development Blog | Twitter
    Help playtest my game, Inferus!
  • 12/08/2009 17:08 In reply to

    Re: There was an error reflecting type 'TileMapEditor.Map'. When trying to save my tile map.

    The Texture2D doesnt cause problems on serialization, but it locks on deseerialization, so yeah, making it private or adding a [XmlIgnore()] there would be a good idea.
    Development Blog: http://gamerrants.blogspot.com
Page 1 of 1 (7 items) Previous Next