continued sprite with states
This commit is contained in:
parent
367886b728
commit
8534498add
|
|
@ -97,7 +97,7 @@ animations = [ {
|
|||
"speed": 10.0
|
||||
}, {
|
||||
"frames": [ SubResource( 14 ), SubResource( 15 ), SubResource( 16 ), SubResource( 17 ), SubResource( 17 ), SubResource( 18 ), SubResource( 14 ), SubResource( 19 ), SubResource( 19 ), SubResource( 19 ) ],
|
||||
"loop": true,
|
||||
"loop": false,
|
||||
"name": "idle",
|
||||
"speed": 11.0
|
||||
} ]
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ var previous_state_frame_number : int
|
|||
var previous_state_name: String
|
||||
var previous_speed_multiplier: float
|
||||
|
||||
var show_frame:bool = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
|
|
@ -46,29 +45,16 @@ func _process(delta):
|
|||
#play()
|
||||
process_animations()
|
||||
|
||||
# Need to detect when animation is finished.
|
||||
# This spit out to the console too many times.
|
||||
# if (frame + 1) == frames.get_frame_count(animation):
|
||||
# print("done.")
|
||||
# asynchronous animation completed check.
|
||||
# if show_frame:
|
||||
# print(frame, "-done.")
|
||||
# show_frame = false
|
||||
# Turns out frame 0 is when animation get signaled.
|
||||
|
||||
#Disabling for now:
|
||||
# if frames.get_animation_loop(animation) == false:
|
||||
# #print("Stop!!!!!", current_state.animation_sequence.size(), " - ", current_state.animation_index)
|
||||
# if current_state.animation_sequence.size() > 0:
|
||||
# #print("<-- next anim.")
|
||||
# current_state.animation_index += 1
|
||||
# if current_state.animation_index >= current_state.animation_sequence.size():
|
||||
# #print("Stop!!!!!")
|
||||
# current_state.animation_finished = true
|
||||
|
||||
func _on_animation_finished():
|
||||
print(frame, "- Frame done (self signaled)")
|
||||
show_frame = true
|
||||
#Disabling for now:
|
||||
if frames.get_animation_loop(animation) == false:
|
||||
#print("Stop!!!!!", current_state.animation_sequence.size(), " - ", current_state.animation_index)
|
||||
if current_state.animation_sequence.size() > 0:
|
||||
#print("<-- next anim.")
|
||||
animation_index += 1
|
||||
if animation_index >= current_state.animation_sequence.size():
|
||||
#print("Stop!!!!!")
|
||||
current_state.animation_finished = true
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ extends Resource
|
|||
export var debug_state: bool = false
|
||||
export var timeout_seconds: float = 0.0
|
||||
|
||||
#signal state_entered()
|
||||
#signal state_exited()
|
||||
signal state_entered()
|
||||
signal state_exited()
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
|
||||
|
|
@ -49,10 +49,12 @@ func enter() -> void:
|
|||
if state_timeout != null:
|
||||
print(name, "-Starting Timer")
|
||||
state_timeout.start()
|
||||
pass
|
||||
emit_signal("state_entered")
|
||||
return
|
||||
|
||||
func exit() -> void:
|
||||
pass
|
||||
emit_signal("state_exited")
|
||||
return
|
||||
|
||||
# Disable to test whether actually needed.
|
||||
#func process_input(_event: InputEvent) -> String:
|
||||
|
|
|
|||
|
|
@ -75,6 +75,11 @@ func change_to_known_state(new_state_name: String) -> void:
|
|||
push_warning(get_parent().name + ": Attempt to switch state to unknown: " + new_state_name)
|
||||
change_state(states_index["default"])
|
||||
|
||||
func get_state_reference(state_name: String) -> State:
|
||||
if states_index.has(state_name):
|
||||
return states_index[state_name]
|
||||
return null
|
||||
|
||||
# Disable to test whether actually needed.
|
||||
## Pass through functions for the Player to call,
|
||||
## handling state changes as needed.
|
||||
|
|
|
|||
|
|
@ -1,32 +1,3 @@
|
|||
class_name StateMachineAnimatedActor extends StateMachine
|
||||
|
||||
## I'm not sure I need a subtype anymore
|
||||
func _ready():
|
||||
print ("ready animactor state machine.")
|
||||
for s in states:
|
||||
print ("sname: ", s.name)
|
||||
var this_state = s
|
||||
if this_state is StateAnimatedActor:
|
||||
print("Adding state ", this_state.name)
|
||||
#check for empty state name
|
||||
if this_state.name != '':
|
||||
#check for unique state name
|
||||
if !(states_index.has(this_state.name)):
|
||||
# call setup
|
||||
this_state.setup()
|
||||
if debug_state_machine:
|
||||
print("Initializing State Node: ", s)
|
||||
this_state.debug_state = true
|
||||
if this_state.state_timeout != null:
|
||||
add_child(this_state.state_timeout)
|
||||
# Add to state index
|
||||
states_index[this_state.name] = this_state
|
||||
else:
|
||||
push_error("Multiple states with same name in: ")
|
||||
else:
|
||||
print("State missing name in: " )
|
||||
|
||||
if states_index.has(starting_state_name):
|
||||
change_state(states_index[starting_state_name])
|
||||
else:
|
||||
push_error("State machine cannot find starting state: " + starting_state_name)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user