Improved performance

This commit is contained in:
2024-02-26 23:50:56 +01:00
parent afab83a35f
commit 885459f5d3
12 changed files with 45 additions and 13 deletions

View File

@ -1,27 +1,30 @@
class_name AnimationComponent
extends Node
var player: AnimationPlayer
var animations: AnimationPlayer
var state: StateComponent
func _ready():
state = owner.get_node("State")
state.transitioned.connect(on_transition)
player = $AnimationPlayer
animations = %AnimationPlayer
func _process(delta):
animations.advance(delta)
func on_transition(_from: StateComponent.State, to: StateComponent.State):
match to:
StateComponent.State.Idle:
player.play("human/idle")
animations.play("human/idle")
StateComponent.State.Run:
player.play("human/run-fast")
animations.play("human/run-fast")
StateComponent.State.Jump:
player.play("human/jump")
animations.play("human/jump")
StateComponent.State.Fall:
player.play("human/fall")
animations.play("human/fall")
StateComponent.State.None:
player.play("human/RESET")
animations.play("human/RESET")
func play(action_name: StringName, speed: float = 1.0):
player.speed_scale = speed
player.play(action_name)
animations.speed_scale = speed
animations.play(action_name)