Easy. You create the animations in the editor by creating a SpriteFrames resource and then use logic to choose the animation.
For instance, assuming you are referencing the object from its parent node:
Var anim = $AnimationPlayer
Anim.play(‘default’)
So the name of the AnimationPlayer node, method is play and in parentheses, a string for your animation. There are other methods too, like
anim.play_backwards(‘default’)
Good note: you can also yield to the animation ending before you trigger other logic. For instance, waiting until a animation is done to add points:
Yield(anim, “animation_finished”)
# next code here
The Godot docs also explain it well but Davidepesce.com also has some good tutorials to give you a visual reference. Also this link: kidscancode tutorial
Also, good note here: signals connected to the node’s own script are great ways to make transitions between animations and since they connect to its own tree normally, they are easy to instance with little code later if you duplicate them.
Signal next_frames
Func _ready():
Self.connect(“next_frames”, self, “on_next_frames”)
Anim.play(‘default’)
And say when a hit runs you emit your signal:
Emit_signal(“next_frames”)
And then put the code you want to run here:
Func on_next_frames():
Anim.play(‘moving’)
And as for the warning for when they are done processing: you generally don’t want to call anim.play() more than once in the same function unless you have some way to sequence them. Generally better to separate these into different pieces of logic (and signals are great for this) and not the same piece of code from what I have learned so far. I have a carnival mini-game/whack-a-mole i am working on and i have managed to transition between moles moving up, down, getting hit and being idle all only using the play() function. All you need to do is plug it into the right sequence of logic using the steps above.