SFML community forums

Help => Graphics => Topic started by: vechestva on June 26, 2014, 11:45:08 pm

Title: How to rotate sprite, keeping the original position?
Post by: vechestva on June 26, 2014, 11:45:08 pm
How to rotate sprite, keeping the original position? Sprite position changes every time. It goes to ~ 300 degrees. :)
Sprite* square;
....
square->SetRotation((float)rand()%360);
 
Title: Re: How to rotate sprite, keeping the original position?
Post by: Laurent on June 26, 2014, 11:50:16 pm
What do you mean? If you just rotate it, its position won't change. Rotation and position are separate attributes. If you mean the visual position, of course it kind of changes when you rotate the sprite, but then I don't know what you mean with "keeping the original position". So please explain your problem better.
Title: Re: How to rotate sprite, keeping the original position?
Post by: vechestva on June 27, 2014, 12:17:25 am
I want that it changed an angle on center. :P
Title: Re: How to rotate sprite, keeping the original position?
Post by: G. on June 27, 2014, 12:54:16 am
Your sprites rotates around its origin, which is by default in (0, 0) its top left corner. If you want it to rotate around its center, set its origin (http://www.sfml-dev.org/documentation/2.1/classsf_1_1Sprite.php#a56c67bd80aae8418d13fb96c034d25ec) to its center. ;)