协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
animation【开发与工程】Create and manage animations in Godot using AnimationPlayer, AnimationTree, Tween, and AnimatedSprite2D. Use this skill when building character animations, UI transitions, sprite frame animations, tween-based effects, or animation state machines.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
extends Node2D
@onready var animation_player = $AnimationPlayer
func _ready():
animation_player.play("walk")
animation_player.play("run", -1, 2.0) # name, blend, speed
func _process(delta):
if animation_player.is_playing():
print(animation_player.current_animation)
func _ready():
animation_player.animation_finished.connect(_on_animation_finished)
animation_player.animation_started.connect(_on_animation_started)
func _on_animation_finished(anim_name: String):
if anim_name == "attack":
state = IDLE
func _on_animation_started(anim_name: String):
print("Started: ", anim_name)
extends Node2D
func _ready():
var tween = create_tween()
tween.tween_property(self, "position", Vector2(100, 0), 1.0)
tween.tween_property(self, "modulate:a", 0.0, 0.5)
tween.tween_callback(queue_free)
func animate_with_options():
var tween = create_tween()
tween.set_ease(Tween.EASE_IN_OUT)
tween.set_trans(Tween.TRANS_CUBIC)
# Parallel animations
tween.tween_property($Sprite, "position", Vector2(100, 0), 1.0)
tween.parallel().tween_property($Sprite, "modulate", Color.RED, 1.0)
# Looped tween
tween.set_loops(3)
tween.tween_interval(0.5)
# Fade in
func fade_in(node: CanvasItem, duration: float = 0.5):
node.modulate.a = 0.0
var tween = create_tween()
tween.tween_property(node, "modulate:a", 1.0, duration)
# Fade out
func fade_out(node: CanvasItem, duration: float = 0.5):
var tween = create_tween()
tween.tween_property(node, "modulate:a", 0.0, duration)
# Scale bounce
func bounce_scale(node: Node2D):
var tween = create_tween()
tween.tween_property(node, "scale", Vector2(1.2, 1.2), 0.1)
tween.tween_property(node, "scale", Vector2(1.0, 1.0), 0.1)
# Move to position
func move_to(target: Node2D, destination: Vector2, duration: float):
var tween = create_tween()
tween.tween_property(target, "position", destination, duration)
extends CharacterBody2D
@onready var animated_sprite = $AnimatedSprite2D
func _physics_process(delta):
if velocity.length() > 0:
animated_sprite.play("walk")
animated_sprite.flip_h = velocity.x < 0
else:
animated_sprite.play("idle")
extends CharacterBody3D
@onready var animation_tree = $AnimationTree
enum State { IDLE, WALK, RUN, JUMP }
var current_state = State.IDLE
func _ready():
animation_tree.active = true
func _physics_process(delta):
animation_tree.set("parameters/Idle/blend_position", velocity.length())
animation_tree.set("parameters/Walk/blend_position", velocity.length())
if is_on_floor():
if velocity.length() > 0:
current_state = State.WALK
else:
current_state = State.IDLE
else:
current_state = State.JUMP