SFML community forums

Help => Graphics => Topic started by: Megatron on September 06, 2011, 02:25:00 am

Title: Rotating on sub-rected/animated sprites
Post by: Megatron 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?
Title: Rotating on sub-rected/animated sprites
Post by: Laurent 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.