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

Author Topic: Rotating on sub-rected/animated sprites  (Read 1283 times)

0 Members and 1 Guest are viewing this topic.

Megatron

  • Newbie
  • *
  • Posts: 22
    • View Profile
Rotating on sub-rected/animated sprites
« on: September 06, 2011, 02:25:00 am »
I have some animated sprites in a project I'm working on. I load a sprite sheet and create a set of subrects for the sheet that represent the various frames. The problem is when I rotate the sprite, it rotates the entire texture, so adding rotation ends up changing the position, even if I set the position after the rotation. For example, I have the follow drawing code


case Timing::Quarter:
               {
                  QuarterArrow[index]->SetRotation(arrow.Rotation);
                  QuarterArrow[index]->SetPosition(arrow.Position);
                  QuarterArrow[index]->Draw(window);
               }
               break;


I do this routine for 4 arrow structs, each of which draws the same sprite. Position is the same for all 4. The structs have rotations of 0, 90, 180 and 270 for the roation value.

I was expecting the 4 sprite to end up directly over top of each other, but instead they are spread out.

I figured I can overcome this by calculating an offset based off the Rotation parameter and offseting position by that, however I was hoping there was some way to do rotation just relative to the subrect, now the entire texture. Is this doable?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Rotating on sub-rected/animated sprites
« Reply #1 on: September 06, 2011, 07:53:44 am »
It's not relative to the entire texture, rotation is centered on (0, 0) by default. You can change that with SetCenter.
Laurent Gomila - SFML developer