How to pause until an animation has finished playing

I have an animation the makes a black square fade in and out that I want to play while loading and unloading collections its a gui animation is this possible
This is what I’m thinking

msg.post(unload current collection)
play animation
-- wait for animation stop
msg.post(load new collection)

Is this possible
Thanks

yes, in the API reference for gui.animate you can see that there’s a [complete-function] parameter:

gui.animate(node,property,to,easing,duration,[delay],[complete_function],[playback])

you can call a function there that will be executed once the animation finishes, so you can do something like this:

gui.animate(node, property, to, easing, duration, [delay], function()
    msg.post(load new collection)
end)

Thanks the function executes but it has stopped the animation from playing. Do you know what might have happened.

That’s weird, do you mean that the function executes before the animation completes and so it gets cancelled?

Can you share your gui.animate code to see better what might be happening?

sorry this took so long but here is the code. i changed something not sure what but now it plays half the animation once then glichly does it any time after that.

function on_message(self, message_id, message, sender)
	if message_id == hash("play") then
		gui.set_enabled(gui.get_node("box_1"), true)
		gui.animate(gui.get_node("box_1"), 'color.w', 1, gui.EASING_LINEAR, 0.5, 0, function ()
			msg.post("/proxys#loader", "load")
			gui.set_enabled(gui.get_node("box_2"), true)
			gui.set_enabled(gui.get_node("box_1"), false)
			gui.animate(gui.get_node("box_2"), "color.w", 0.5, gui.EASING_LINEAR, 0.5, 0, function ()
				gui.set_enabled(gui.get_node("box_2"), false)
			end)
		end)
	end
end

this is what i want it to be doing

animate box_1 to alpha 1 
	show box_2
	hide box_1
	init/enable new collection
animate box_2 to alpha .5
	hide box_2

thanks

I’m looking at this on my phone at the moment but it looks like the code should work fine.

the issue seems to be that (at least the piece of code you shared) you don’t “reset” the animated values after the animation is done:

  • when you animate the alpha of the node, that final value of the animation (in this case 1) becomes the new value of the node

  • when you enable the node again the node has alpha of 1 and the animation it’s actually playing but it’s animating “color.w” from 1 to… 1 so nothing really changes

when you disable the node you should also reset back to 0 (or whatever you need it to be) the property

animate box_1 to alpha 1 
	show box_2
	hide box_1
    SET ALPHA OF box_1 BACK TO 0
	init/enable new collection
animate box_2 to alpha .5
	hide box_2
    SET ALPHA OF box_2 BACK TO 0

Ok thanks

it no longer glitches but the fade in still doesn’t work. Thanks for all the help so far