Go.animate executes only once (SOLVED)

Hi,

I’ve created a brand new “Mobile template” project and trying to rotate my sprite on touch event. For some reasons it rotates only first time I touch the screen. All next touches are registered (I see “Touch” in the console) but the sprite does not rotate anymore…

function on_input(self, action_id, action)
	if action_id == hash("touch") and action.pressed then		
		go.animate("switch", "euler.z", go.PLAYBACK_ONCE_FORWARD, -90, go.EASING_LINEAR, 0.5)
		print("Touch!")
	end
end
1 Like

Rotation is to absolute values. Your code rotates to Z angle -90 and not current rotation minus 90. Subsequent rotations will start at -90 and go to -90 - i.e. no rotation.

4 Likes

I believe it’s because the code doesn’t rotate the sprite by -90 degrees but to -90 degrees. Subsequent calls “rotate” it again, but the rotation is the same as the way the sprite already is rotated, so you can’t see anything.

You should probably change the -90 to a relative rotation based on the sprite’s current rotation.

Edit: What sicher said.

3 Likes

so, in my case I want to rotate the sprite to 45 degrees on each touch indefinitely, could you please give me an example?

Something like this:

local rot = go.get("switch", "euler.z")
go.animate("switch", "euler.z", go.PLAYBACK_ONCE_FORWARD, rot + 45, go.EASING_LINEAR, 0.5)
6 Likes

works great, thanks a lot!

2 Likes

Good luck with your project! Let us know how it goes

1 Like