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

Author Topic: Rotate sprite and preserve position  (Read 1144 times)

0 Members and 1 Guest are viewing this topic.

terabin

  • Newbie
  • *
  • Posts: 4
    • View Profile
Rotate sprite and preserve position
« 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 :/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Rotate sprite and preserve position
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/