Jump to content
  • Advertisement
Sign in to follow this  
Alian Vesuf

SFML - Layers of Tiles

This topic is 2074 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.


Share this post

Link to post
Share on other sites

Obviously yes! two quick ideas:

  • You could use for each layer for example an extra Surface/Sprite and blit on it
    • If you don't want it more you can stop drawing
    • or delete it
  • You could give them an group ID
    • stop drawing the group if you don't want them anymore.
    • release the group (delete it)

It only about organizing, i think.

Edited by exOfde

Share this post

Link to post
Share on other sites

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).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!