Find out last animation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By grettyr
:warning: Old Version Published before Godot 3 was released.

Hello,

I have a scene which contains a sprite which contains an animationplayer.
While running I add several of those sprite-scenes to my current tree. (via add_child()) and start the animation of some of them.

In order to realize when the animation of the animationplayer is finished I listen to the “_on_animation_finished” signal. This works well. The only problem is:

Since I have several animations I get several answers. Each for every instanciated scene where I started the animation.

Is there any way to find out if a finished animation is the final of all animations started?

thanks in advance,
grettyr

:bust_in_silhouette: Reply From: timoschwarzer

This is possible by just counting the animations:

var animation_count = 0

Now you increment this number every time you start an animation:

animation_count += 1

In your function connected to the _on_animation_finished signal, you decrement this number and check if this was the last animation:

animation_count -= 1
if animation_count == 0:
    print("This was the last animation")

Thanks for your answer. I was hoping for a “more elegant” solution but this will do.

grettyr | 2017-06-08 11:36