AnimationPlayer
- Game Development course
- Expert
- Lesson 26/47
- 4 min
Learn to play animation clips with AnimationPlayer.
What is AnimationPlayer?
AnimationPlayer is the Godot node that plays animation clips. Each clip defines value changes over a certain time range. AnimationTree plays these clips through AnimationPlayer.
player.play("yurume")Without this node animations cannot be shown on screen.
Animation clips
An animation clip is made of keyframes on a timeline. Each keyframe holds a value record at a specific moment. A specific clip is played with the play() method and the clip name is given as a parameter.
player.play("kosma")Moving between clips is the task of the AnimationTree.
Practice Play an animation clip
In a script named Oynatma, define a variable named player of type AnimationPlayer and assign the $AnimationPlayer node in _ready. Then start the animation with player.play("yurume") and print the text "Animasyon basladi" with print.
Starter code
extends Node
var player: AnimationPlayer
func _ready():
player = $AnimationPlayer
# player uzerinden "yurume" animasyonunu oynat
# "Animasyon basladi" metnini yazdirSample solution
extends Node
var player: AnimationPlayer
func _ready():
player = $AnimationPlayer
player.play("yurume")
print("Animasyon basladi")Expected output
Animasyon basladi
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does the play() method of AnimationPlayer do?
- It deletes the animation clip
- It pauses the animation
- It reloads the animation tree
- It plays the specified animation clip Correct answer
Explanation: The play() method starts playing the animation clip whose name is given.
2 Play the animation clip
player.____("yurume")
player.play("yurume")
Explanation: In AnimationPlayer, the method that plays a clip is named play.
3 AnimationPlayer terms
| Term | Meaning |
|---|---|
AnimationPlayer |
The node that plays animation clips |
Klip |
Animation data with keyframes |
play() |
Plays the specified clip |
Keyframe |
A value record at a specific moment |