Play the animation and yield:
if life == 0:
$Spritezada.play("Dead");
yield($Spritezada, "animation_finished");
print("died");
queue_free();
The above code will play the animation, then halt the execution. When the animation player raises the signal animation_finished
it will resume, print "died"
and set the current node for removal (queue_free
).
By the way, the animation_finished
signal passes a text parameter. If you do not want to use yield
as suggested above, write your code like so:
func _on_Spritezada_animation_finished(anim_name: String):
if anim_name == "Dead":
queue_free();
I believe Godot should be telling you about that missing parameter. If you don't see a message about that, double check you connected the correct signal.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…