+1 vote

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

asked May 20, 2018 in Engine by camarones (101 points)

1 Answer

+2 votes
Best answer

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)
        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
answered May 20, 2018 by Diet Estus (1,504 points)
selected May 21, 2018 by camarones
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.