0 votes

Here's a paste of the code. The rpint statements are there to help me debug.

func explode():
print("explode called")
if $AnimatedSprite.is_playing():
    print("still playing")
    print($AnimatedSprite.animation)
    yield(get_node("AnimatedSprite"), "animation_finished")
print("finished")
queue_free()

In the above code, "finished" is only printed if the animation is actively playing at the point it reaches the if conditional (if the current frame < final frame). In that case, the yield works as expected. It waits, then continues to the print statement and the queue_free.

If the animation has already finished (current frame = last frame) by the time it reaches the $AnimatedSprite.is_playing conditional, it still returns true (the print statements both show) but the yield doesn't return.

So it appears as if the animationfinished signal is not being called on an animation that has already finished, even though isplaying is still considered true.

Any idea what I'm doing wrong here?

asked Jun 11 in Engine by alwaysusa (67 points)

1 Answer

+1 vote
Best answer

You should connect the animation_finished signal of the animation player to a function to do what you're trying to achieve. I think is_playing will be false only if you call the stop() method so that is no use for you in this case.

Also make sure your animation is not a loop.

answered Jun 11 by jtarallo (376 points)
selected Jun 11 by alwaysusa

Ah I see! I misunderstood how is_playing was called. I implemented your suggestion, and it all works. Thank you!

Glad to help! Good luck!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.