Improved animation performance

This commit is contained in:
2024-02-28 12:15:58 +01:00
parent ded6f51c5d
commit cb4dd41358
9 changed files with 63 additions and 52 deletions

View File

@ -1,12 +1,10 @@
class_name AnimationComponent
extends CharacterComponent
@export var skip_frames: int = 0
var animations: AnimationPlayer
var state: StateComponent
var accumulated_delta: float
var skipped_frames: int
var delay: float
func _ready():
state = character.get_node("State")
@ -16,12 +14,9 @@ func _ready():
func _process(delta: float):
accumulated_delta += delta
if skipped_frames >= skip_frames:
if accumulated_delta >= delay:
animations.advance(accumulated_delta)
accumulated_delta = 0
skipped_frames = 0
else:
skipped_frames += 1
func on_transition(_from: StateComponent.State, to: StateComponent.State):
match to: