In a 2D tile-based game, how should NPCs and tiles reference each other?

Posted by lezebulon on Game Development See other posts from Game Development or by lezebulon
Published on 2011-11-12T19:47:40Z Indexed on 2011/11/13 2:09 UTC
Read the original article Hit count: 200

Filed under:
|
|

I'm making a tile engine for 2D games (seen from the top). Basically the world is composed of a grid of tiles. Now I want to put for instance NPCs that can move on the map.

What do you think is best: 1) each tile has a pointer to the NPC that is on its tile, or a NULL pointer 2) having a list of NPCs, and they have the coordinates of the tile they are on. 3) something else?

1) is faster for collision detection but it would use much more memory space and it is slower to find all NPCs in a map. 2) is the opposite.

thanks

© Game Development or respective owner

Related posts about engine

Related posts about tiles