This topic is 4700 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am in the easly stages of designing a 2D adventure game. Something like Zelda becuase I don't like RPG's as much. Anyways thats not really important. What my question is is what is the most efficent way of keeping a map in memory. I was thinking on useing a way where you have a 2D array of n elements and each element is a linked list header. Each linked list is a tile and each node in the linked list is a level of tiles. I got this idea from a gamedev article and was wondering if it was used anymore (by the people actually makeing 2D games anymore=)) and if it was a good way of approching things. If not is there a better way?

##### Share on other sites
If you head for a tile based system, you best store your maps as simple a 2d arrays of data for simple loading and saving. You can have multiple layers as well. I wouldn't be concerned about memory consumption - early consoles like the SNES supported up to four tile layers and only had 32KiB RAM for them [smile].
You can just divide larger areas into sectors and reload the map data on the fly if memory really is a concern.
Just do the math - assume you have four tile layers and 8 bit entries in your map to allow for 255 distinct tiles (zero being reserved for transparent tiles):

A map of 128 x 128 tiles would result in 128 * 128 * 4 = 64KiB of memory [smile].
Given a tile size of 16 x 16 pixels this would provide you with a virtual screen of 2048 x 2048 pixels.

Say you want a virtual screen of 16384 x 16384 pixels, that would still only be a 1024 x 1024 tile map and results in 4MiB of tile memory.
Given the amount of RAM on an average office machine, this would be more than acceptable while still keeping your code simple and provide for fast load times (since no further processing is required).

HTH,
Pat.

##### Share on other sites
Thanks for the info. I think I was trying to be a little to memory frugal, if you will. Is there a type of site like rentacoder but for visual art?

##### Share on other sites
I would store the map as a grid of bytes, where each byte indexes into a tile palette (one of 256 possible tiles). I'd store a separate list of "special" things to draw or do at different locations, with the actual location for each thing, and scan that list after drawing the base tile map. It's likely to be a fairly short list compared to storing more than a byte per map location.

If that's too cumbersome (say, you have a giant world), then I would store something like a 64x64 square of map tiles like described above, and then store an upper level of either a hash grid, a list, or a simple grid of pointers to each of the smaller maps -- the benefit being that for oddly-shaped worlds, you don't need to store smaller maps for parts that the player can't get to (ocean, deep forest, or whatever).

##### Share on other sites
Quote:
 Thanks for the info. I think I was trying to be a little to memory frugal, if you will. Is there a type of site like rentacoder but for visual art?

Not sure, but you might want to look into RM2K graphics. The tiles are all 16x16 (maybe 20x20?) and look great in Zelda-style worlds. There's also rips of many SNES tilesets availible, often converted into RM2K formats, but you can convert them back. Check www.phylomortis.com for some.

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633338
• Total Posts
3011419
• ### Who's Online (See full list)

There are no registered users currently online

×