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

Author Topic: Sprite composition and transformation  (Read 2773 times)

0 Members and 1 Guest are viewing this topic.

uGhster

  • Newbie
  • *
  • Posts: 23
    • View Profile
Sprite composition and transformation
« on: January 08, 2013, 08:07:18 pm »
Is this possible...

Let's say I have a class that extends sf::Sprite and implements void draw(sf::RenderTarget& target, sf::RenderStates states).
And in draw(..) I render a couple of sprites that move and what not.

is it possible to do a setPosition of the class and have the rendered content translate accordingly?

What is the correct way of doing this?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Sprite composition and transformation
« Reply #1 on: January 08, 2013, 08:18:04 pm »
Of course it's possible, but I wouldn't extend sf::Sprite but derive from sf::Drawable and sf::Transformable and then you simply have to apply the translation of your class to all the sprites within your class.

See the example in the documentation.
« Last Edit: January 08, 2013, 08:19:54 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

uGhster

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Sprite composition and transformation
« Reply #2 on: January 08, 2013, 08:23:12 pm »
I don't know if my description of the problem was insufficient. I figured out how to solve it...

in the drawMethod I did as suggested in documentation for transformable:

virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
{
   states.transform *= getTransform();
   target.draw(..., states);
}

 

This would add the transformations for the sprite onto the composed sprites drawn in draw!

:D
« Last Edit: January 08, 2013, 08:24:56 pm by uGhster »

uGhster

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Sprite composition and transformation
« Reply #3 on: January 08, 2013, 08:24:20 pm »
Which is what you suggested eXpl0it3r :D
Thanks!