I want to animate a moving go. If I put go.animate in the init function, I lose the movement in the update function (mainly because of the “to” property of te animate function, I think). So, how can I make a moving go bounce?
You could still do it in init() using the animation playback mode set to loop ping pong:
It isn’t working. I have made a plane that moves through the screen on the x axis. At the and of the screen it decends down a bit on the y axis and starts moving backwards on the x axis. So basically it’s a plane that flies through the screen and gets lower and lower row by row. If I animate the plane in the init function, it won’t decend on the y axis at the end of each row anymore.
this is my movement:
function update(self, dt)
commonMod.planePos = go.get_position()
if commonMod.planePos.x <= 80 and commonMod.planePos.y == 600 then
self.speed.x = self.speed.x * 1.1
go.animate(".", "position.y", go.PLAYBACK_LOOP_PINGPONG, commonMod.planePos.y - 10, go.EASING_INQUAD, 1.5)
end
if commonMod.planePos.x <= 80 and commonMod.planePos.y < 600 then
if self.speed.x < 0 then
self.speed.x = -self.speed.x
end
self.speed.x = self.speed.x * 1.1
commonMod.planePos.y = commonMod.planePos.y - 40
go.animate(".", "position.y", go.PLAYBACK_LOOP_PINGPONG, pos.y - 10, go.EASING_INQUAD, 1.5)
end
if commonMod.planePos.x >= 920 then
self.speed.x = self.speed.x * -1.1
commonMod.planePos.y = commonMod.planePos.y - 40
end
sprite.set_hflip("#plane_sprite", self.speed.x < 0)
go.set_position(commonMod.planePos + self.speed * dt)
end
Ok, I figured it out!
At the beginning of each row I have to cancel the animation first. This cancels the animation, the plane can jump down on the y axis and I can restart the animation for that given row.
1 Like