SFML community forums

Help => General => Topic started by: terabin on May 21, 2018, 08:34:14 pm

Title: Rotate sprite and preserve position
Post by: terabin on May 21, 2018, 08:34:14 pm
Hello!
I want to rotate a sprite in it's own center, my try:

         sf::Sprite sprite(*internalTexture[t].texture, sf::IntRect(rect[0], rect[1], rect[2], rect[3]));

         sprite.setPosition(sf::Vector2f(x, y));
         sprite.move(sf::Vector2f(offx * -1, offy * -1));

         if (opacity < 255)
         {
            sprite.setColor(sf::Color(255, 255, 255, opacity));
         }

         if (rotation > 0.0)
         {
            sprite.setOrigin(sf::Vector2f(rect[2] / 2, rect[3] / 2));
            sprite.setRotation(-rotation);
         }


Actually the position of the sprite is not preserved :/
Title: Re: Rotate sprite and preserve position
Post by: eXpl0it3r on May 21, 2018, 11:12:24 pm
Well if you change the origin, then the sprites origin will be different and thus the position will change. The origin doesn't just apply to rotations.