Rotating after flipping sprite causes the sprite to rotate wrong

Right now I have a sprite that I rotate and it works fine until I flip it, then it rotates all wrong. Is there something I have to do after I call setImageFlip() so that it rotates the same but just with the image flipped? Or any advice on how to fix this?
(I am also using Whitebrim's AnimatedSprite for the head sprite)

You can see in the gif the player serving has the expected head rotation. When the player on the right goes to spike, the flipped head sprite rotates unexpectedly.
head_roate_gif

function AimBodyParts:init(character, headOffsetX, headOffsetY, armOffsetX, armOffsetY)
    local head_img = gfx.imagetable.new('Images/Characters/fire_girl-aiming_head')
    local arm_img = gfx.image.new('Images/Characters/fire_girl-aiming_arm')
    
    self.character = character
    self.headOffsetX = headOffsetX
    self.headOffsetY = headOffsetY

    self.rotation = 0
    self.flipped = false

    -- Animated head sprite
    self.head_sprite = AnimatedSprite.new(head_img)
    self.head_sprite:addState('spike', 1, 4, {tickStep = 5})
    self.head_sprite:setZIndex(character:getZIndex() + 1)
    self.head_sprite:setCenter(0.5, 1)
    self.head_sprite:moveTo(self.character.x + self.headOffsetX, self.character.y + self.headOffsetY)
    self.head_sprite:playAnimation()

    if character.x > 200 then
        self:flipSprites()
    end

    self:add()
end

function AimBodyParts:flipSprites()
    self.head_sprite:setStates({
        {
            name = "default",
            flip = gfx.kImageFlippedX
        }
    })
    self.headOffsetX = -self.headOffsetX
    self.flipped = true
end

function AimBodyParts:update()
    self:updateAnimation()

    local aim = math.atan(self.character.ball.y - self.arm_sprite.y, self.character.ball.x - self.arm_sprite.x)
    self.rotation = math.deg(aim)
    if self.flipped then
        self.rotation = 180 - self.rotation
    end

    self.head_sprite:setRotation(self.rotation)
end
1 Like

Might be off the mark, but self.rotation = 180 - self.rotation seems wrong.
I suspect you want one of:
self.rotation *= -1
self.rotation += 180
self.rotation -= 180
But without actually running it I can’t be sure.

Appreciate the help. The code uses 180 - self.rotation to adjust for the flipped sprite so that the back of the head isn't facing the ball.
The issue I'm having is that the character head is looking at the ball properly, but appearing to rotate around a different pivot point. The un-flipped head (character serving on the left) is rotating properly around its center point of (0.5, 1) but the spiking character on the right does not appear to rotate around that same center point.

Another developer has tried something similar and has told me that this appears to be a bug in the sdk.

If anyone has any other insight please let me know, but as for now I'll just have to make a set of flipped heads and import them

1 Like

What happens if you re-set the centre point after setting the new rotation?

Same thing, still rotates incorrectly.

Have tagged this as a bug report

1 Like

Sounds good, thank you!

Gotcha.

Yeah, it’s a bug.
Left is sprite with center at 0.5, 1, rotating clockwise
Right is flipped sprite (flipX) with center at 0.5, 1, rotating anti-clockwise.
IMG_2402

3 Likes

I noticed that too, for me even a simple 90 degree rotation distorts the source image

im rotating externlly for now

That's what I am doing now as well. Although I saw that 2.5.0 released today and saw some stuff about rotations in there so I was going to see if something for this issue got pushed through.