From c23fe774a3afe4a179270934f5c305e53ba0e87a Mon Sep 17 00:00:00 2001 From: Nitsud Yarg Date: Sat, 15 Jun 2024 14:36:34 -0700 Subject: [PATCH] Struggling with animations again. --- src/playerD/Player.tscn | 4 ++-- src/state_animated_actor.gd | 26 +++++++++++++++++--------- src/state_machine_animated_actor.gd | 7 ++++++- src/state_modifier.gd | 1 + 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/playerD/Player.tscn b/src/playerD/Player.tscn index 21459bc..1ba7c31 100644 --- a/src/playerD/Player.tscn +++ b/src/playerD/Player.tscn @@ -490,7 +490,7 @@ player_number = 1 position = Vector2( -1, -51 ) frames = SubResource( 190 ) animation = "idle" -frame = 34 +frame = 32 flip_h = false __meta__ = { "_aseprite_wizard_config_": { @@ -548,7 +548,7 @@ draw_weapon_node = NodePath("../draw_weapon") script = ExtResource( 9 ) animation_name = "jump" starting_frame = 6 -timeout_seconds = 0.1 +pre_append_animation = true [node name="draw_weapon" type="Node" parent="movement_state_machine" index="6"] script = ExtResource( 9 ) diff --git a/src/state_animated_actor.gd b/src/state_animated_actor.gd index 314efde..9408591 100644 --- a/src/state_animated_actor.gd +++ b/src/state_animated_actor.gd @@ -33,6 +33,7 @@ var animation_index: int = 0 var current_animation_sequence: int = 0 var animation_suffix: String = ''; +var mod_animation_sequence = [PoolStringArray()] var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity") @@ -57,6 +58,8 @@ func _ready(): func enter() -> void: # animations.connect("animation_finished", self, "_on_AnimatedSprite_animation_finished") + mod_animation_sequence.clear() + mod_animation_sequence = animation_sequence.duplicate(true) # Reset animation suffix in case there isn't one animation_suffix = '' if debug_state: @@ -67,21 +70,26 @@ func enter() -> void: if modifier_stack_ref.empty() == false: # a modifier is applied if modifier_stack_ref[-1].animation_name != '': # the first one has an animation if modifier_stack_ref[-1].animation_suffix: # it's a suffix type - if animation_sequence.size() > 0: # the current animation is multipart (sequence > 0) + if mod_animation_sequence.size() > 0: # the current animation is multipart (sequence > 0) animation_index = 0 current_animation_sequence = 0 # Guess I don't need this one anymore #if animations.frames.get_animation_names().has(animation_sequence[animation_index] + modifier_stack_ref[-1].animation_name): - if animations.frames.has_animation(animation_sequence[animation_index] + modifier_stack_ref[-1].animation_name): + if animations.frames.has_animation(mod_animation_sequence[animation_index] + modifier_stack_ref[-1].animation_name): animation_suffix = modifier_stack_ref[-1].animation_name + elif modifier_stack_ref[-1].pre_append_animation == true: # it's a pre-append type + #animation_sequence.size() + print ("DEBUG: A prepend animation") + #mod_animation_sequence = animation_sequence + mod_animation_sequence.push_front(modifier_stack_ref[-1].animation_name) else: animations.play(modifier_stack_ref[-1].animation_name) animations.frame = modifier_stack_ref[-1].starting_frame return - if animation_sequence.size() > 0: + if mod_animation_sequence.size() > 0: animation_index = 0 current_animation_sequence = 0 - animations.play(animation_sequence[animation_index] + animation_suffix) + animations.play(mod_animation_sequence[animation_index] + animation_suffix) return func exit() -> void: @@ -94,17 +102,17 @@ func process_input(_event: InputEvent) -> State: func process_frame(_delta: float) -> State: #if animation_sequence.size() > 0 and current_animation_sequence != animation_index: - if animation_sequence.size() > animation_index and current_animation_sequence != animation_index: - if animation_index >= animation_sequence.size(): - animation_index = 0 + if mod_animation_sequence.size() > current_animation_sequence and current_animation_sequence != animation_index: +# if animation_index >= mod_animation_sequence.size(): +# animation_index = 0 ##TODO: Add a safety check here. - animations.play(animation_sequence[animation_index] + animation_suffix) + animations.play(mod_animation_sequence[animation_index] + animation_suffix) if debug_state: print("An animation sequence: ", animations.animation , animation_index) current_animation_sequence = animation_index # We have no more sequence animations and the current one doesn't loop # we do this to prevent the default idle animation from playing. - if animation_index >= animation_sequence.size() and animations.frames.get_animation_loop( + if animation_index >= mod_animation_sequence.size() and animations.frames.get_animation_loop( animations.animation) == false: animations.stop() diff --git a/src/state_machine_animated_actor.gd b/src/state_machine_animated_actor.gd index f7bbf79..996e03e 100644 --- a/src/state_machine_animated_actor.gd +++ b/src/state_machine_animated_actor.gd @@ -25,7 +25,7 @@ func process_frame(delta: float) -> void: # We could iterate through a whole list of states but I'm not sure i want # states to be that complex. if state_modifiers.empty() == false: - if state_modifiers[-1].state_timeout.time_left == 0: + if state_modifiers[-1].state_timeout.time_left == 0 and state_modifiers[-1].pre_append_animation == false: if debug_state_machine: print("Pop State Modifier: ", state_modifiers[-1].name) state_modifiers.pop_back() @@ -44,6 +44,11 @@ func process_frame(delta: float) -> void: func _on_AnimatedSprite_animation_finished(): + if state_modifiers.empty() == false: + if state_modifiers[-1].pre_append_animation == true: + if debug_state_machine: + print("Pop State Modifier: ", state_modifiers[-1].name) + state_modifiers.pop_back() if current_state.animations.frames.get_animation_loop( current_state.animations.animation) == false: if current_state.animation_sequence.size() > 0: diff --git a/src/state_modifier.gd b/src/state_modifier.gd index a978e32..ba0f508 100644 --- a/src/state_modifier.gd +++ b/src/state_modifier.gd @@ -20,6 +20,7 @@ export var timeout_seconds: float = 0.0 # Attempting to use this as an animation suffix that can linger after # state transition like 'run-fire' to 'idle-fire' 'jump-fire' etc. export var animation_suffix: bool = false +export var pre_append_animation: bool = false # not sure if I can do the array thing from state change. Maybe? # disabling this sequencing for now.