AnimatedSprite animation not playing when other animation is playing

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


I have this script that plays a flashing animation when an enemy is hit by a bullet:

func _on_Area2D_body_entered(body):
  if isDead: return

  if body.get_name() == "BulletType01":
  if body.get_name() == "PlayerShipRed":

  health -= 1

  if health <= 0:
	isDead = true

As you can see, I’m trying to trigger another animation when the enemy’s health reaches 0 or below. However, if the hit animation is playing, it seems as though the death animation is not being played. This is confirmed by the fact that the death animation works every time if I comment out the hit animation.

Any help is appreciated,

Thank you!

I cannot reproduce your problem. Can you provide an example project with the issue at hand?

njamster | 2020-05-04 11:25

Of course! Here is a link to the github repo:

GitHub - XavierGerD/Star-Blaster

Just open and run Scene/Main_Game/Main.tscn. Shoot enemies. You should notice death animations are not always playing. The same thing happens if you collide with enemies, your ship should explode but it doesn’t always.

Thanks for your help!

XavierGerD | 2020-05-04 13:01

:bust_in_silhouette: Reply From: njamster

You have to do this:

func _on_Enemy01Sprite_animation_finished():
	if $Enemy01Sprite.get_animation() == "explode":

instead of just this:

func _on_Enemy01Sprite_animation_finished():

or you will free the enemy-node already when the first hit-animation finishes.

Thank you! It works!

Follow up question: The same thing is happening with the player ship. If you collide with enemies, you take damage, eventually your ship should explode. But right now, it seems as though the animation doesn’t play if you’re already playing one of the tilt animations.

Any clues?

XavierGerD | 2020-05-04 14:31

Similar problem. Change this:

func _on_PlayerMovementTween_tween_all_completed():

into this:

func _on_PlayerMovementTween_tween_all_completed():
	if not $PlayerShipRed.get_animation() == "explode":

njamster | 2020-05-04 14:59

Amazing! You are a true wizard! Thank you so much :smiley:

XavierGerD | 2020-05-04 15:19