I want to render a tile-based map and I am not sure which class structure to use to keep logic and rendering separeted.
My class structure so far on the logic side: One abstract parent class Tile
with an attribute int tileType
and one class extending Tile for every kind of tile. Every of the extending class defines the value, for example in the class Tree extends Tile
I have tileType = 2
and in the class Wall extends Tile
I have tileType = 3
.
When I render a map, I go through the array of tiles and do something like this:
switch (tileType) {
...
case 2: texture = treeTexture; break;
case 3: texture = wallTexture; break;
...
}
draw(texture, x, y);
I wonder if the class structure makes sense and if this is a good solution to render tiles? Or what other solutions are there to render tiled maps while keeping logic and rendering separated?