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.
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