Loading...
Loading...
Animate in Godot 4.x three ways: AnimationPlayer for keyframed clips (incl. call and signal tracks), AnimationTree with state machines and blend spaces for character animation, and Tween for short procedural/UI tweens via create_tween(). Use when working with AnimationPlayer/AnimationTree nodes in a .tscn, blending character states, sprite-sheet animation, or code-driven Tweens.
npx skill4agent add gamedev-skills/awesome-gamedev-agent-skills godot-animationAnimationPlayerAnimationTreeTweengodot-2d-movementgodot-ui-controlgodot-shadersAnimationPlayerAnimationTreeAnimationPlayerTweencreate_tween()AnimatedSprite2DSpriteFramesframeAnimationPlayerAnimationPlayerAnimationTreeactive = trueanim_playerAnimationNodeStateMachineAnimationNodeBlendSpace2Dtravelanimation_finished@onready var anim: AnimationPlayer = $AnimationPlayer
func attack() -> void:
anim.play("attack")
await anim.animation_finished # resume after the clip ends
anim.play("idle")@onready var tree: AnimationTree = $AnimationTree
func _ready() -> void:
tree.active = true # the tree drives animation; AnimationPlayer is the source
func set_state(state: StringName) -> void:
# The playback object controls an AnimationNodeStateMachine root.
var sm: AnimationNodeStateMachinePlayback = tree.get("parameters/playback")
sm.travel(state) # transitions using the graph's connections
func _physics_process(_d: float) -> void:
set_state(&"run" if velocity.length() > 5.0 else &"idle")# Root is an AnimationNodeBlendSpace2D named "Move" with idle/run points placed in it.
func update_locomotion(input_dir: Vector2) -> void:
# Parameter path = "parameters/<node name>/blend_position".
tree.set("parameters/Move/blend_position", input_dir)func pop_in(node: Control) -> void:
node.scale = Vector2.ZERO
node.modulate.a = 0.0
var tw := create_tween() # bound to this node's tree
tw.set_parallel(true) # run the two tweens together
tw.tween_property(node, "scale", Vector2.ONE, 0.2) \
.set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_OUT)
tw.tween_property(node, "modulate:a", 1.0, 0.2) # sub-property via ":"AnimationTree.activetravel()active = trueanim_player"parameters/<NodeName>/...""parameters/playback""parameters/Move/blend_position"AnimationTreeAnimationPlayer.play()Tweencreate_tween()Tweencreate_tween()set_loops()yieldyield(anim, "...")await anim.animation_finished"modulate:a""position:x"SpriteFramesAnimatedSprite2Dreferences/animation-tree-and-tween.mdgodot-2d-movementgodot-ui-controlgodot-3d-essentialsgame-ai