SFML community forums

Help => Graphics => Topic started by: DunklesTier on March 08, 2012, 05:28:35 am

Title: SFML 2 Forcing Sprites to draw at top
Post by: DunklesTier on March 08, 2012, 05:28:35 am
Is there any way of forcing a Sprite to be drawn to the screen in a different level than RenderWindow.Draw(Sprite) is called?

Ex.  Sprite 1 and Sprite 2 have the same position.  Is there a way to tell the RenderWindow to draw Sprite1 on top of Sprite2 even if I call my RenderWindow's Draw function to draw Sprite1 first?
Title: SFML 2 Forcing Sprites to draw at top
Post by: Laurent on March 08, 2012, 08:06:45 am
Quote
Is there any way of forcing a Sprite to be drawn to the screen in a different level than RenderWindow.Draw(Sprite) is called?

No. The only way would be to call your own Draw, which put the sprite in a sorted queue and then flushing it at the end, calling SFML's Draw.
Title: SFML 2 Forcing Sprites to draw at top
Post by: Jove on March 08, 2012, 10:42:40 am
I did this by adding a variable called 'Priority' to the game object code. Its range was only 0-4 but provided the key which Laurent spoke of.

At render time, the sprites were drawn according to priority level, 0 being furthest away (first to be drawn), and 4 being the closest (last to be drawn).
Title: SFML 2 Forcing Sprites to draw at top
Post by: Orwel on March 09, 2012, 12:01:56 am
For this problem, you need use layer
A class is present in wiki :wink:
Title: Thanks
Post by: DunklesTier on March 10, 2012, 03:10:33 pm
Thanks a lot everyone, I'm going to use the priority system implementation suggested.  And Laurent, great engine, by the way.