Hello. While working with Tiled editor and experimenting with filestream in C++ to load maps i noticed that Tiled editor can separate tiles into layers. An idea came to my mind, wouldn't be awesome to display tiles on screen based on layers they are living on. For example i can have a layer on screen with an array of tiles on it. If i destroy this layer all of the tiles inside of it would be destroyed. This could give you more control over objects in your map that are related to each other. Say for example you are fighting enemies and you kill their boss, all of he's army should be destroyed, which means that if you destroy parent layer you destroy all child objects living on it.

So i want to know if there is a possible way to display tiles in SFML based on layers. This can also be effective if you need to draw tiles over tiles, which will give depth and z index to objects on screen.

An example sketch of what i mean

I know that you can draw sprites on top of sprites by changing the order of the draw logic but what i want is how we can basically group tiles so that you can destroy them by destroying the layer they are living on and not iterate through each one of them.

You can simply draw first every tile in layer 0, then the ones in layer 1 and so on.

It is quite common to subdivide layers with a kind of logic:

0 -> very background (distant) objects (more subdivision on this layer can get parallax effect)

1 -> terrain layer

2 -> pickable objects (coins, monsters, player) (in Tiled, this is more an Object layer than a Tile layer)

3 -> front objects

if you place your character on layer 2 it will be rendered above the 2 back layers, but covered by everything in the layer 3, for example (and it could collide with objects on layer 2 and 1, but ignore the ones on layer 0 and 3).

Using Tiled, I also duplicate collidable layer into 2: one for tiles and one for objects (rects to use for bounding box collisions).