It is easy to keep track of what tile of a tilemap tiny game objects are in. What is not as straight forward is how to sort larger objects objects into a tilemap such that each tile that contains part of them has a reference to the object – especially when the objects are moving and the tilemap has to be kept up to date.
While Tilemaps are a great way of storing level data for a variety of games, we can use them for much more than storing level geometry.
We can use tilemaps as an accelerating data structure for many other systems like physics and AI, by keeping track of what objects are contained within each tile of the tilemap.
Not every game that uses tilemaps has the game’s coordinate systems correspond exactly to the tiles. We can write a wrapper class around our tilemap to convert between tiles and world coordinates.
Tilemaps can be a great way to keep track of our game world. While a simple array of tile data at their core, they can be much more than that. Today I will look into the concept of directions in a tilemap, how we can perform local steps between tiles easily, and what more we can do once we are that far.
Reusability and modularity is an important aspect of software design, as it can speed up development of future projects significantly. This also holds in game development, as we will show with the example of a generic tilemap class we are going to implement here.