Struggling with animations again.
This commit is contained in:
parent
9d69d7df7d
commit
c23fe774a3
|
|
@ -490,7 +490,7 @@ player_number = 1
|
||||||
position = Vector2( -1, -51 )
|
position = Vector2( -1, -51 )
|
||||||
frames = SubResource( 190 )
|
frames = SubResource( 190 )
|
||||||
animation = "idle"
|
animation = "idle"
|
||||||
frame = 34
|
frame = 32
|
||||||
flip_h = false
|
flip_h = false
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_aseprite_wizard_config_": {
|
"_aseprite_wizard_config_": {
|
||||||
|
|
@ -548,7 +548,7 @@ draw_weapon_node = NodePath("../draw_weapon")
|
||||||
script = ExtResource( 9 )
|
script = ExtResource( 9 )
|
||||||
animation_name = "jump"
|
animation_name = "jump"
|
||||||
starting_frame = 6
|
starting_frame = 6
|
||||||
timeout_seconds = 0.1
|
pre_append_animation = true
|
||||||
|
|
||||||
[node name="draw_weapon" type="Node" parent="movement_state_machine" index="6"]
|
[node name="draw_weapon" type="Node" parent="movement_state_machine" index="6"]
|
||||||
script = ExtResource( 9 )
|
script = ExtResource( 9 )
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ var animation_index: int = 0
|
||||||
var current_animation_sequence: int = 0
|
var current_animation_sequence: int = 0
|
||||||
var animation_suffix: String = '';
|
var animation_suffix: String = '';
|
||||||
|
|
||||||
|
var mod_animation_sequence = [PoolStringArray()]
|
||||||
|
|
||||||
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
|
var gravity: int = ProjectSettings.get_setting("physics/2d/default_gravity")
|
||||||
|
|
||||||
|
|
@ -57,6 +58,8 @@ func _ready():
|
||||||
|
|
||||||
func enter() -> void:
|
func enter() -> void:
|
||||||
# animations.connect("animation_finished", self, "_on_AnimatedSprite_animation_finished")
|
# 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
|
# Reset animation suffix in case there isn't one
|
||||||
animation_suffix = ''
|
animation_suffix = ''
|
||||||
if debug_state:
|
if debug_state:
|
||||||
|
|
@ -67,21 +70,26 @@ func enter() -> void:
|
||||||
if modifier_stack_ref.empty() == false: # a modifier is applied
|
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_name != '': # the first one has an animation
|
||||||
if modifier_stack_ref[-1].animation_suffix: # it's a suffix type
|
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
|
animation_index = 0
|
||||||
current_animation_sequence = 0
|
current_animation_sequence = 0
|
||||||
# Guess I don't need this one anymore
|
# 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.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
|
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:
|
else:
|
||||||
animations.play(modifier_stack_ref[-1].animation_name)
|
animations.play(modifier_stack_ref[-1].animation_name)
|
||||||
animations.frame = modifier_stack_ref[-1].starting_frame
|
animations.frame = modifier_stack_ref[-1].starting_frame
|
||||||
return
|
return
|
||||||
if animation_sequence.size() > 0:
|
if mod_animation_sequence.size() > 0:
|
||||||
animation_index = 0
|
animation_index = 0
|
||||||
current_animation_sequence = 0
|
current_animation_sequence = 0
|
||||||
animations.play(animation_sequence[animation_index] + animation_suffix)
|
animations.play(mod_animation_sequence[animation_index] + animation_suffix)
|
||||||
return
|
return
|
||||||
|
|
||||||
func exit() -> void:
|
func exit() -> void:
|
||||||
|
|
@ -94,17 +102,17 @@ func process_input(_event: InputEvent) -> State:
|
||||||
|
|
||||||
func process_frame(_delta: float) -> State:
|
func process_frame(_delta: float) -> State:
|
||||||
#if animation_sequence.size() > 0 and current_animation_sequence != animation_index:
|
#if animation_sequence.size() > 0 and current_animation_sequence != animation_index:
|
||||||
if animation_sequence.size() > animation_index and current_animation_sequence != animation_index:
|
if mod_animation_sequence.size() > current_animation_sequence and current_animation_sequence != animation_index:
|
||||||
if animation_index >= animation_sequence.size():
|
# if animation_index >= mod_animation_sequence.size():
|
||||||
animation_index = 0
|
# animation_index = 0
|
||||||
##TODO: Add a safety check here.
|
##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:
|
if debug_state:
|
||||||
print("An animation sequence: ", animations.animation , animation_index)
|
print("An animation sequence: ", animations.animation , animation_index)
|
||||||
current_animation_sequence = animation_index
|
current_animation_sequence = animation_index
|
||||||
# We have no more sequence animations and the current one doesn't loop
|
# We have no more sequence animations and the current one doesn't loop
|
||||||
# we do this to prevent the default idle animation from playing.
|
# 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.animation) == false:
|
||||||
animations.stop()
|
animations.stop()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
# We could iterate through a whole list of states but I'm not sure i want
|
||||||
# states to be that complex.
|
# states to be that complex.
|
||||||
if state_modifiers.empty() == false:
|
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:
|
if debug_state_machine:
|
||||||
print("Pop State Modifier: ", state_modifiers[-1].name)
|
print("Pop State Modifier: ", state_modifiers[-1].name)
|
||||||
state_modifiers.pop_back()
|
state_modifiers.pop_back()
|
||||||
|
|
@ -44,6 +44,11 @@ func process_frame(delta: float) -> void:
|
||||||
|
|
||||||
|
|
||||||
func _on_AnimatedSprite_animation_finished():
|
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(
|
if current_state.animations.frames.get_animation_loop(
|
||||||
current_state.animations.animation) == false:
|
current_state.animations.animation) == false:
|
||||||
if current_state.animation_sequence.size() > 0:
|
if current_state.animation_sequence.size() > 0:
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ export var timeout_seconds: float = 0.0
|
||||||
# Attempting to use this as an animation suffix that can linger after
|
# Attempting to use this as an animation suffix that can linger after
|
||||||
# state transition like 'run-fire' to 'idle-fire' 'jump-fire' etc.
|
# state transition like 'run-fire' to 'idle-fire' 'jump-fire' etc.
|
||||||
export var animation_suffix: bool = false
|
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?
|
# not sure if I can do the array thing from state change. Maybe?
|
||||||
# disabling this sequencing for now.
|
# disabling this sequencing for now.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user