30 lines
794 B
GDScript3
Raw Normal View History

2024-02-07 23:04:19 +01:00
class_name AnimationComponent
extends Node
2024-02-26 23:50:56 +01:00
var animations: AnimationPlayer
2024-02-15 13:45:17 +01:00
var state: StateComponent
2024-02-07 23:04:19 +01:00
func _ready():
2024-02-15 16:28:27 +01:00
state = owner.get_node("State")
2024-02-15 13:45:17 +01:00
state.transitioned.connect(on_transition)
2024-02-26 23:50:56 +01:00
animations = %AnimationPlayer
func _process(delta):
animations.advance(delta)
2024-02-15 13:45:17 +01:00
func on_transition(_from: StateComponent.State, to: StateComponent.State):
match to:
StateComponent.State.Idle:
2024-02-26 23:50:56 +01:00
animations.play("human/idle")
2024-02-15 13:45:17 +01:00
StateComponent.State.Run:
2024-02-26 23:50:56 +01:00
animations.play("human/run-fast")
2024-02-15 13:45:17 +01:00
StateComponent.State.Jump:
2024-02-26 23:50:56 +01:00
animations.play("human/jump")
2024-02-15 13:45:17 +01:00
StateComponent.State.Fall:
2024-02-26 23:50:56 +01:00
animations.play("human/fall")
2024-02-15 13:45:17 +01:00
StateComponent.State.None:
2024-02-26 23:50:56 +01:00
animations.play("human/RESET")
2024-02-15 13:45:17 +01:00
func play(action_name: StringName, speed: float = 1.0):
2024-02-26 23:50:56 +01:00
animations.speed_scale = speed
animations.play(action_name)