Runing animations one by one in different nodes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By websterek

I have bunch of dots, all of them are generated from tool and I would like to animate them one after another with little delay.
Right now I’m using yield function with timer. But it’'s not perfect. Generally this dots are indicators of a button, when it’s pressed they are changing color from first to the last but if player release the button they should back to original state. Sadly if you are pressing and releasing button rapidly this function seems to works incorrectly for my purposes (like few last dot’s are starting early etc.).

Right now my code looks like this:

func turn_on():
	for child in activate_nodes:
		yield(timer, "timeout")

func turn_off():
	for child in activate_nodes:

And here is sample scene:
enter image description here

How can I achieve this effect correctly? The best for me will be animating it from first to last but if button is released it’s animating back to beginning state (even if only part of them will be activated).

Let me see if I’m understanding what you’re saying.

What you want is a way to turn the colour of one button into another colour, and with a little delay, do the same for the next one, and repeat for the rest.

And when they’re released, put them back in the same color all at once?

SIsilicon | 2018-09-25 13:49

Yes, mostly, it’s need to be animated sprites because few next objects will be slightly different but action/reaction process will be still the same

websterek | 2018-09-25 14:09

:bust_in_silhouette: Reply From: SIsilicon

Ok then what you could do is give those button nodes an animation.
In Godot, you can not only animate variables/properties of nodes, but you can also animate method callbacks. This can be used here.

  1. Add a regular keyframe to change the sprite’s current frame/colour
  2. Add another keyframe but this time in a callback track. Which calls the method change_adjacent.

change_adjacent looks like this.

func change_adjacent():
    has_changed = true
    #assuming they all share a common parent node-
    var max_index = get_parent().get_child_count() - 1
    if get_index()+1 <= max_index:
        var next_node = get_parent().get_child(get_index+1)
        if not next_node.has_changed:"change_colour")
    if get_index()-1 >= 0:
        var prev_node = get_parent().get_child(get_index-1)
        if not prev_node.has_changed:"change_colour")

The animation called change_colour is the one I described earlier. Look in the docs to see how to make a callback track. To trigger this animation to begin with make some code to detect when the particular button is pressed. I’m sure you have something like that already. And as for releasing, just put all of these nodes in a group and call get_tree.call_group("your group name", "your reset method name")