Skip to content

Commit 011d4ee

Browse files
committed
CharacterSpriteBehavior: Reset frames when back to idle
The townies "idle" has a subtle up and down animation. For a character made of parts, since the last commit one part (like the head) may keep playing "idle" while another (like the legs) may play "walk". But when the character is back to idle, all parts should be set in sync again. Otherwise, the head may go up when the legs go down, making a funny but not desired (for now) dance.
1 parent 84e9842 commit 011d4ee

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

scenes/game_logic/sprite_behaviors/character_sprite_behavior.gd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extends BaseSpriteBehavior
1919
## Use this when using more advanced animation through an AnimationPlayer node.
2020
@export var play_animations: bool = true
2121

22+
var _previous_character_velocity: Vector2
2223
var _is_character_running: bool = false
2324

2425

@@ -48,7 +49,9 @@ func _process(delta: float) -> void:
4849
func _process_animations(_delta: float) -> void:
4950
if character.velocity.is_zero_approx():
5051
sprite.speed_scale = 1.0
51-
sprite.play(&"idle")
52+
if not _previous_character_velocity.is_zero_approx():
53+
sprite.play(&"idle")
54+
sprite.set_frame_and_progress(0, 0.0)
5255
else:
5356
if _is_character_running:
5457
if sprite.sprite_frames.has_animation(&"run"):
@@ -60,6 +63,7 @@ func _process_animations(_delta: float) -> void:
6063
else:
6164
sprite.speed_scale = 1.0
6265
sprite.play(&"walk" if sprite.sprite_frames.has_animation(&"walk") else &"idle")
66+
_previous_character_velocity = character.velocity
6367

6468

6569
func _notification(what: int) -> void:

0 commit comments

Comments
 (0)