How do I play two sprite animations at the same time?

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

I have the frames of a Sprite animated by an AnimationPlayer (a character running) in Godot 3.0. I have another animation to be played when the character takes damage, where the sprite visibility is toggled on and off to produce a flashing effect. How can I play both animations at the same time? Do I use an AnimationTreePlayer?

Thanks in advance

:bust_in_silhouette: Reply From: Diet Estus

You should use two AnimationPlayers as children of your Sprite.

The first will play the main animations and the second will play the effect animations.

Here is the structure:

KinematicBody2D (or whatever your main node is)
    Sprite
        AnimationPlayer1 (for your spritesheet)
        AnimationPlayer2 (for your effects)

You should create a reference to the first animation player and call it something like anim_player and create a reference to the second animation player and call it something like effect_player. Then you can reference them to play whatever animations you want in your code.

For example, in your main node script:

onready var anim_player = get_node("Sprite/AnimationPlayer1")
onready var effect_layer = get_node("Sprite/AnimationPlayer2")

func take_damage(amount):
    # lower health
    health -= amount
    # play correct animations
    anim_player.play("knockback_animation")
    effect_player.play("blink")