Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML 2 Forcing Sprites to draw at top  (Read 3858 times)

0 Members and 1 Guest are viewing this topic.

DunklesTier

  • Newbie
  • *
  • Posts: 2
    • View Profile
SFML 2 Forcing Sprites to draw at top
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2 Forcing Sprites to draw at top
« Reply #1 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.
Laurent Gomila - SFML developer

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
SFML 2 Forcing Sprites to draw at top
« Reply #2 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).
{much better code}

Orwel

  • Full Member
  • ***
  • Posts: 208
    • View Profile
SFML 2 Forcing Sprites to draw at top
« Reply #3 on: March 09, 2012, 12:01:56 am »
For this problem, you need use layer
A class is present in wiki :wink:

DunklesTier

  • Newbie
  • *
  • Posts: 2
    • View Profile
Thanks
« Reply #4 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.

 

anything