All
This commit is contained in:
@@ -10,6 +10,26 @@ extends Node2D
|
||||
@onready var shoes: AnimatedSprite2D = $Shoes
|
||||
|
||||
var all_parts: Array[AnimatedSprite2D]
|
||||
var current_animation := "idle-down"
|
||||
var is_flipped := false
|
||||
|
||||
# Public Methods
|
||||
func UpdateSprite() -> void:
|
||||
var current_state := state_machine.GetCurrentState()
|
||||
var current_direction := direction_component.GetCurrentDirection()
|
||||
var animation := _build_animation_name(current_state, current_direction)
|
||||
var should_flip := _should_flip_horizontal()
|
||||
|
||||
if animation == current_animation and should_flip == is_flipped:
|
||||
return
|
||||
|
||||
current_animation = animation
|
||||
is_flipped = should_flip
|
||||
|
||||
for part in all_parts:
|
||||
part.animation = animation
|
||||
part.play()
|
||||
part.flip_h = should_flip
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
@@ -17,12 +37,7 @@ func _ready() -> void:
|
||||
base, hair, pants, hands, shoes
|
||||
]
|
||||
|
||||
var animation := _build_animation_name(state_machine.GetCurrentState(), direction_component.GetCurrentDirection())
|
||||
var should_flip := _should_flip_horizontal()
|
||||
for part in all_parts:
|
||||
part.animation = animation
|
||||
part.play()
|
||||
part.flip_h = should_flip
|
||||
UpdateSprite()
|
||||
|
||||
|
||||
func _build_animation_name(state: PlayerStateMachine.States, direction: Enums.Directions) -> String:
|
||||
|
||||
@@ -15,5 +15,5 @@ func _ready() -> void:
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
func _process(_delta: float) -> void:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user