What tile storage method is best for tile-based game?

by John Smith   Last Updated February 26, 2016 03:05 AM

I am making a simple tile based game. The tiles are Ground and Wall. The entities (dynamic objects) are Box and Player. I am storing tiles as 2d array of enum variables and both Box and Player has own class that extends abstract Entity. Box are saved as list. While doing my level editor I have faced with several problems like check if tile already has some entity in it, is tile solid or soft and so on. What approach is better: to store tiles like entities (each tile in own object that contains it's own position and possibly contains link to an entity and objects are saved as list) or like 2d array and always cycle through it to make some check?

Tags : storage tile


Answers 1


There is never one best method. Only the method which works best for you and your game.

But most tile-oriented game engines I know use a 2d array of integer values for each static map layer where each entry represents the tile-type at a given tile-coordinate pair. When your tiles have more properties than can be expressed with a single ID value, this 2d array can also hold a whole structure or object per tile with all the relevant information. This can also include a reference to the mobile object which occupies it (or the list of occupying entities if your game mechanics require that) .

If tiles do not manage their occupants, then mobile objects are usually stored in a simple list which is ordered by the desired drawing order. If you have a very (very!) large number of mobile objects, you might instead use a BSP tree so you can quickly get all objects on a point or in an area.

Philipp
Philipp
February 23, 2016 18:51 PM

Related Questions



Disc based storage medium

Updated February 23, 2017 06:13 AM


SNES Limitations: Number of stored Graphics?

Updated May 19, 2017 19:13 PM