3
\$\begingroup\$

I'm been working on a 2D tile game (sidescroller perspective) and I decided to rework my tile engine. Right now I store a new tile instance per block in the world (so there are like 1000 TileStone instances in memory). My plan was to change the current tile engine so that I store only a small object which tells the renderer a stone tile should be drawn there. The TileStone, TileDirt classes only store the block properties like hardness, texture and so on.

With this design I ran into a bit of a problem, some tiles, for example, a chest tile should be able to store custom data like the contents of the chest, or for instance a windmill block which needs to update all of its logic every update tick.

What would be a good way of implementing a tile engine, that meets these requirements?

Programming language: Java, Library: LibGDX

Thanks in advance -ProRed

\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

It sounds to me like you should also be divorcing the concept of a container or logic object or whatever else from the tile. The tiles should just be able the static (or mostly static) structure of the world.

Things like containers and windmills and whatever, which are significantly heavier-weight, should be non-tile objects stored in your world differently, and given a tile position to indicate where they (currently) are on the map.

But they're not actually tiles themselves (even if they point to similar-looking data for drawing purposes so that they render like tiles).

Then you can add extra data to them without worrying about bloating any tile-related storage that would otherwise not need it (for containers), and you can group them all in their own big contiguous array and update them all at once (windmills), et cetera.

\$\endgroup\$

You must log in to answer this question.

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