0
\$\begingroup\$

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.

\$\endgroup\$
0

1 Answer 1

0
\$\begingroup\$

Item is a class, the Tile class only stores a reference to it.

Your items are static instanced, so you have a few, and the tiles are sharing them... so the name is shared by all the tiles, is the same name for all tiles that are linked to the same Item.

You know that you have to make chunks and split the map... go for it.

\$\endgroup\$
1
  • \$\begingroup\$ Thats what I was thinking, but I created a test class, and one with a Byte instead of an item made it significantly smaller. Then again, I think it's because I was serializing to get the size. \$\endgroup\$
    – Cyral
    Nov 25, 2012 at 0:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .