Chaining gui / go animations

Example of how to chain multiple gui (and go) animate together for future searchers.

gui.animate(gui.get_node("star"),"scale", vmath.vector3(0.5,0.5,0.5), gui.EASING_OUTBOUNCE, 1.1, 0, function()
	gui.animate(gui.get_node("star"),"scale", vmath.vector3(0.6,0.6,0.6), gui.EASING_INOUTSINE, 1.1, 0, nil, gui.PLAYBACK_LOOP_PINGPONG)
end)

9 Likes

And if you want to chain many you could leverage coroutines to avoid very deeply nested chains of callbacks:

local function gui_animate(node, prop, to, easing, duration, delay, playback)
	local co = coroutine.running()
	assert(co, "Only call this from within a coroutine")
	gui.animate(node, prop, to, easing, duration, delay, function()
		-- resume the coroutine now that the animation is finished
		coroutine.resume(co)
	end, playback)
	-- pause the coroutine until resumed (when animation is finished)
	coroutine.yield()
end

-- create a coroutine and run it
coroutine.wrap(function()
	gui_animate(gui.get_node("star"),"scale", vmath.vector3(0.5,0.5,0.5), gui.EASING_OUTBOUNCE, 1.1, 0)
	gui.animate(gui.get_node("star"),"scale", vmath.vector3(0.6,0.6,0.6), gui.EASING_INOUTSINE, 1.1, 0, gui.PLAYBACK_LOOP_PINGPONG)
end)()

The above be wrapped into a module to get a nice API. And there’s an asset that works on go animations: https://www.defold.com/community/projects/117048/

11 Likes