Gui.animation a rotation.z only works if original rotation is reset

self.chimp_node = gui.get_node("chimp")
...
    if action.released and gui.pick_node(self.chimp_node, action.x, action.y) then
        gui.cancel_animation(self.chimp_node, "rotation.z")
        gui.set_rotation(self.chimp_node, self.chimp_rotation)
        gui.animate(self.chimp_node, "rotation.z", 360, gui.EASING_OUTEXPO, 1, 0, function() 
            gui.set_rotation(self.chimp_node, self.chimp_rotation)
            print("animation done")
        end)
    end

This works, but if you do not restore the rotation to the original value before trying to animate it again it does nothing when attempting to do more spins. Probably because it’s already at 360. But this may confuse someone else at first in the future so posting here so it can be searched.

I get what you are saying but modifying the rotation is not treated differently from other properties. We do nothing to keep the rotation within 0 and 359 degrees. If you want to spin something another 360 degrees you need to add to the existing rotation. Something like this:

local rot = gui.get_rotation(self.chimp_node)
rot.z = rot.z + 360
gui.animate(self.chimp_node, "rotation.z", rot, gui.EASING_OUTEXPO, 1, 0)

You could also clamp it yourself after the animation has completed:

gui.animate(self.chimp_node, "rotation.z", 360, gui.EASING_OUTEXPO, 1, 0, function() 
    local rot = gui.get_rotation(self.chimp_node)
    rot.z = rot.z % 360
    gui.set_rotation(self.chimp_node, rot)
end)
3 Likes

If you don’t need to change the value on each restart, you could use the gui.PLAYBACK_LOOP_FORWARD playback mode to continuously play it.

2 Likes