Animated Sprite "is_playing" always returning true?

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

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 animation_finished signal is not being called on an animation that has already finished, even though is_playing is still considered true.

Any idea what I’m doing wrong here?

:bust_in_silhouette: Reply From: jtarallo

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.

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

alwaysusa | 2020-06-11 22:52

Glad to help! Good luck!

jtarallo | 2020-06-12 02:52