Jump to content

  • Log In with Google      Sign In   
  • Create Account


SFML - Layers of Tiles


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 aliasc   Members   -  Reputation: 180

Like
0Likes
Like

Posted 12 February 2014 - 01:21 AM

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

sdf.png

 

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.

 



Sponsor:

#2 exOfde   Members   -  Reputation: 808

Like
0Likes
Like

Posted 12 February 2014 - 03:57 AM

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, 12 February 2014 - 03:59 AM.


#3 arka80   Members   -  Reputation: 733

Like
0Likes
Like

Posted 12 February 2014 - 04:09 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS