Storing large array of tiles, but allowing easy access to data

Posted by Cyral on Game Development See other posts from Game Development or by Cyral
Published on 2012-11-24T21:59:02Z Indexed on 2012/11/24 23:21 UTC
Read the original article Hit count: 194

Filed under:
|
|
|
|

I've been thinking about this for a while. I have a 2D tile bases platformer in XNA with a large array of tile data, I've been running into memory problems with large maps. (I will add chunks soon!)

Currently, Each tile contains an Item along with other properties like how its rotated, if it has forground / background, etc.

An Item is static and has properties like the name, tooltip, type of item, how much light it emits, the collision it does to player, etc. Examples:

public class Item
{
    public static List<Item> Items;

    public Collision blockCollisionType;
    public string nameOfItem;
    public bool someOtherVariable,etc,etc

    public static Item Air
    public static Item Stone;
    public static Item Dirt;
    static Item()
    {
       Items = new List<Item>() 
       { 
            (Stone = new Item()
            {
                nameOfItem = "Stone",
                blockCollisionType = Collision.Solid,
            }),
            (Air = new Item()
            {
                nameOfItem = "Air",
                blockCollisionType = Collision.Passable,
            }),

        };
    }
}

Would be an Item, The array of Tiles would contain a Tile for each point,

public class Tile
{
     public Item item; //What type it is
     public bool onBackground;
     public int someOtherVariables,etc,etc
}

Now, Most would probably use an enum, or a form of ID to identify blocks. Well my system is really nice just to find out about an item. I can simply do tiles[x,y].item.Name To get the name for example. I realized my Item property of the tile is over 1000 Bytes! Wow! What I'm looking for is a way to use an ID (Int or byte depending on how many items) instead of an Item but still have a method for retreiving data about the type of item a tile contains.

© Game Development or respective owner

Related posts about XNA

Related posts about c#