SFML community forums

Help => Graphics => Topic started by: uGhster on January 08, 2013, 08:07:18 pm

Title: Sprite composition and transformation
Post by: uGhster 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?
Title: Re: Sprite composition and transformation
Post by: eXpl0it3r 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 (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Transformable.php#details).
Title: Re: Sprite composition and transformation
Post by: uGhster 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
Title: Re: Sprite composition and transformation
Post by: uGhster on January 08, 2013, 08:24:20 pm
Which is what you suggested eXpl0it3r :D
Thanks!