Jump to content
  • Advertisement
Sign in to follow this  
ichineko

How does one rotate a sprite about a point in SFML?

This topic is 2009 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm blown away by how much trouble I'm having with this. There's obviously some assumptions in the API I'm not understanding.

lets say I have a sprite that's 64x64 pixels, and I want to rotate the *center* of this sprite about a point that is outside the sprite itself, expressed in terms of the global coordinate system (ie, top left corner).

How does one go about doing this without calculating the rotations manually?

I've tried playing around with SetOrigin, but I obviously don't know what the purpose of this thing is. The documentation states it's the center for various transformations.

I don't know what it is I'm missing, but this is frustrating, not the least of which is because I could multiply out the transformations myself. I understand the math, I just don't understand what the hell this API is doing.

Share this post


Link to post
Share on other sites
Advertisement
figured it out
[source lang="cpp"]
sf::transform t;
t.rotate(angle,x,y);

sf::Rect<float> new_rect = t.transformRect(my_sprite.getGlobalBounds());
my_sprite.setPosition(new_rect.left,new_rect.top);
[/source]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!