Gui.animate chaining (SOLVED)

Do I have to chain animations on the same property using the callback function or coroutines?

This does not seem to produce the effect I would expect:

gui.animate(self.combo_start, "position.x", 320, gui.EASING_INOUTQUART, 0.5)
gui.animate(self.combo_start, "position.x", -960, gui.EASING_INOUTQUART, 0.5, 1.5)

expected: node moves to position.x 320, waits 1.5 secs and then moves to position.x -960
result: nodes waits 1.5 secs and then moves to position.x -960

I am not sure but I would say that the second animation cancel the first one

(and in any case, the second animation wait only 1.0 since the first one has to complete).

The following code do what you want:

gui.animate(self.combo_start, “position.x”, 320, gui.EASING_INOUTQUART, 0.5, 0.0,
function()
gui.animate(self.combo_start, “position.x”, -960, gui.EASING_INOUTQUART, 0.5)
end)

@roccosaienz is correct. What happens is that you start one animation and immediately after start another animation which cancels the first.

Here’s a Lua module that will help you do it: https://github.com/britzl/ludobits/blob/master/ludobits/m/sequence.lua

Usage:

local sequence = require "sequence"

sequence.run_once(function()
	sequence.gui_animate(self.combo_start, "position.x", 320, gui.EASING_INOUTQUART, 0.5)
	sequence.gui_animate(self.combo_start, "position.x", -960, gui.EASING_INOUTQUART, 0.5, 1.5)
end)
2 Likes

Here’s the documentation:

If the node property is already being animated, that animation will be canceled and replaced by the new one

1 Like

right! Thanks everyone, this makes sense

Ludobits seems like a great little module, does a lot of things I find really useful. Bookmarked!

Yes there’s a bunch of stuff in there, some good, some bad. It’s a place where I experiment with various solutions to Defold problems. Some things make it into their own official Defold projects.

1 Like

I use this solution for chaining GUI animations

2 Likes