function init(self)
go.property("speed", 8)
msg.post(".", "acquire_input_focus")
go.animate(".", "euler.z", go.PLAYBACK_LOOP_FORWARD, 360, go.EASING_LINEAR, 60/self.speed)
end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
self.speed=self.speed+20
go.cancel_animations("fish1", "euler.z")
go.animate("fish1", "euler.z", go.PLAYBACK_LOOP_FORWARD, 360, go.EASING_LINEAR, 60/self.speed)
end
end
I wish fish1 would spin faster with each click. But it doesn’t. Why?
Isn’t the problem that you click at any point in the rotation, not only when exactly at 0? Example:
You click when the fish has rotated 270 degrees at which point you cancel the animation
When you start the new animation it starts from where it was cancelled (from 270 degrees) and rotates the remaining 90 degrees over the same time it should have rotated a full 360.
The quick’n’dirty solution is to get the rotation when it is cancelled and rotate 360 degrees from that value:
self.speed=self.speed+20
go.cancel_animations("fish1", "euler.z")
local rot = go.get("fish1", "euler.z")
local to = rot + 360
go.animate("fish1", "euler.z", go.PLAYBACK_LOOP_FORWARD, to, go.EASING_LINEAR, 60/self.speed)
You can only have a single animation running for a property. I can’t remember if the system will ignore a call to go.animate() for a property if that property is already animating or if it will replace the running animation.