Fix node order in actor template for better ready() processing. Add signal based callback.
This commit is contained in:
parent
c577a74061
commit
c2ad46f5ae
|
|
@ -19,3 +19,4 @@ position = Vector2( 208, 20 )
|
||||||
shape = SubResource( 1 )
|
shape = SubResource( 1 )
|
||||||
|
|
||||||
[node name="PlayerE" parent="." instance=ExtResource( 1 )]
|
[node name="PlayerE" parent="." instance=ExtResource( 1 )]
|
||||||
|
position = Vector2( 112, 56 )
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ onready var sound_effect_player: AudioStreamPlayer = $SE_Player
|
||||||
onready var movement_component: Movement_StateReceiver = $Movement_StateReceiver
|
onready var movement_component: Movement_StateReceiver = $Movement_StateReceiver
|
||||||
|
|
||||||
#onready var movement_state_machine: StateMachineAnimatedActor = $movement_state_machine
|
#onready var movement_state_machine: StateMachineAnimatedActor = $movement_state_machine
|
||||||
onready var movement_state_machine: StateMachine = $movement_state_machine
|
onready var movement_state_machine: StateMachine = $Movement_StateMachine
|
||||||
|
|
||||||
var sound_effects_dict: Dictionary
|
var sound_effects_dict: Dictionary
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,10 @@ func _ready():
|
||||||
request_state_change = funcref(get_node(callable_state_machine), 'change_to_known_state')
|
request_state_change = funcref(get_node(callable_state_machine), 'change_to_known_state')
|
||||||
get_node(callable_state_machine).connect("state_changed", self,"_on_state_change")
|
get_node(callable_state_machine).connect("state_changed", self,"_on_state_change")
|
||||||
self.connect("animation_finished",self,"_on_animation_finished")
|
self.connect("animation_finished",self,"_on_animation_finished")
|
||||||
|
|
||||||
|
#set current state since State machine might have set state before this
|
||||||
|
# processed
|
||||||
|
current_state = get_node(callable_state_machine).current_state
|
||||||
|
|
||||||
# Sprites should only have a process function
|
# Sprites should only have a process function
|
||||||
# but if I have this will the sprite still animate?
|
# but if I have this will the sprite still animate?
|
||||||
|
|
@ -43,6 +47,10 @@ func _process(delta):
|
||||||
print("You're out of time! I saw it!")
|
print("You're out of time! I saw it!")
|
||||||
request_state_change.call_func('idle')
|
request_state_change.call_func('idle')
|
||||||
#play()
|
#play()
|
||||||
|
else:
|
||||||
|
print("what, no current_state?")
|
||||||
|
if has_method('_state_process_' + current_state.name):
|
||||||
|
call('_state_process_' + current_state.name)
|
||||||
process_animations()
|
process_animations()
|
||||||
|
|
||||||
func _on_animation_finished():
|
func _on_animation_finished():
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ func change_to_known_state(new_state_name: String) -> void:
|
||||||
change_state(states_index["default"])
|
change_state(states_index["default"])
|
||||||
|
|
||||||
func get_state_reference(state_name: String) -> State:
|
func get_state_reference(state_name: String) -> State:
|
||||||
|
print ("what you want? ", state_name)
|
||||||
if states_index.has(state_name):
|
if states_index.has(state_name):
|
||||||
return states_index[state_name]
|
return states_index[state_name]
|
||||||
return null
|
return null
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@
|
||||||
collision_layer = 2
|
collision_layer = 2
|
||||||
script = ExtResource( 8 )
|
script = ExtResource( 8 )
|
||||||
|
|
||||||
|
[node name="Movement_StateMachine" type="Node" parent="."]
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="AnimatedSprite_StateReceiver" type="AnimatedSprite" parent="."]
|
[node name="AnimatedSprite_StateReceiver" type="AnimatedSprite" parent="."]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
|
|
@ -30,7 +33,4 @@ callable_state_machine = NodePath("../Movement_StateMachine")
|
||||||
script = ExtResource( 5 )
|
script = ExtResource( 5 )
|
||||||
callable_state_machine = NodePath("../Movement_StateMachine")
|
callable_state_machine = NodePath("../Movement_StateMachine")
|
||||||
|
|
||||||
[node name="Movement_StateMachine" type="Node" parent="."]
|
|
||||||
script = ExtResource( 2 )
|
|
||||||
|
|
||||||
[node name="SE_Player" type="AudioStreamPlayer" parent="."]
|
[node name="SE_Player" type="AudioStreamPlayer" parent="."]
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
extends AnimatedSprite_StateReceiver
|
extends AnimatedSprite_StateReceiver
|
||||||
|
|
||||||
|
|
||||||
# Declare member variables here. Examples:
|
|
||||||
# var a = 2
|
|
||||||
# var b = "text"
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready():
|
func _ready():
|
||||||
pass # Replace with function body.
|
# Lets see if this nutty thing works
|
||||||
|
var state_ref :State = get_node(callable_state_machine).get_state_reference('idle')
|
||||||
|
state_ref.connect("state_entered", self, "_on_state_entered_idle")
|
||||||
|
# It works but node order really mattered.
|
||||||
|
# State machine needed to be processed first probably for ready function.
|
||||||
|
# good to know!
|
||||||
|
|
||||||
|
# I don't need this right now but I proved it can be done!
|
||||||
|
#func _state_process_idle():
|
||||||
|
# print("I got called!")
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
func _on_state_entered_idle():
|
||||||
#func _process(delta):
|
print("Anim Knows Idle State Entered!")
|
||||||
# pass
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
extends StateMachine
|
|
||||||
|
|
||||||
|
|
||||||
# Declare member variables here. Examples:
|
|
||||||
# var a = 2
|
|
||||||
# var b = "text"
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready():
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
#func _process(delta):
|
|
||||||
# pass
|
|
||||||
|
|
@ -1,16 +1,5 @@
|
||||||
extends Movement_StateReceiver
|
extends Movement_StateReceiver
|
||||||
|
|
||||||
|
|
||||||
# Declare member variables here. Examples:
|
func _state_process_idle():
|
||||||
# var a = 2
|
print("I got called!")
|
||||||
# var b = "text"
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready():
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
#func _process(delta):
|
|
||||||
# pass
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
[ext_resource path="res://lib/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://lib/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://assets/actors/players/playerE/PlayerE_SpriteFrames.tres" type="SpriteFrames" id=2]
|
[ext_resource path="res://assets/actors/players/playerE/PlayerE_SpriteFrames.tres" type="SpriteFrames" id=2]
|
||||||
[ext_resource path="res://src/actors/players/playerE/PlayerE.gd" type="Script" id=3]
|
[ext_resource path="res://src/actors/players/playerE/PlayerE.gd" type="Script" id=3]
|
||||||
[ext_resource path="res://src/actors/players/playerE/PlayerE-Movement_StateMachine.gd" type="Script" id=4]
|
[ext_resource path="res://src/actors/players/playerE/states/idle.tres" type="Resource" id=4]
|
||||||
[ext_resource path="res://src/actors/players/playerE/PlayerE-AnimatedSprite_StateReceiver.gd" type="Script" id=5]
|
[ext_resource path="res://src/actors/players/playerE/PlayerE-AnimatedSprite_StateReceiver.gd" type="Script" id=5]
|
||||||
[ext_resource path="res://src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd" type="Script" id=6]
|
[ext_resource path="res://src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd" type="Script" id=6]
|
||||||
|
|
||||||
|
|
@ -14,7 +14,11 @@ extents = Vector2( 7, 14 )
|
||||||
script = ExtResource( 3 )
|
script = ExtResource( 3 )
|
||||||
actor_type = "Player"
|
actor_type = "Player"
|
||||||
|
|
||||||
[node name="AnimatedSprite_StateReceiver" parent="." index="0"]
|
[node name="Movement_StateMachine" parent="." index="0"]
|
||||||
|
starting_state_name = "idle"
|
||||||
|
states = [ ExtResource( 4 ) ]
|
||||||
|
|
||||||
|
[node name="AnimatedSprite_StateReceiver" parent="." index="1"]
|
||||||
frames = ExtResource( 2 )
|
frames = ExtResource( 2 )
|
||||||
script = ExtResource( 5 )
|
script = ExtResource( 5 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
|
|
@ -31,12 +35,9 @@ __meta__ = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="Movement_StateReceiver" parent="." index="1"]
|
[node name="Movement_StateReceiver" parent="." index="2"]
|
||||||
script = ExtResource( 6 )
|
script = ExtResource( 6 )
|
||||||
|
|
||||||
[node name="Movement_StateMachine" parent="." index="2"]
|
|
||||||
script = ExtResource( 4 )
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="4"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="4"]
|
||||||
position = Vector2( 0, 2 )
|
position = Vector2( 0, 2 )
|
||||||
shape = SubResource( 1 )
|
shape = SubResource( 1 )
|
||||||
|
|
|
||||||
18
src/actors/players/playerE/states/idle.tres
Normal file
18
src/actors/players/playerE/states/idle.tres
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
[gd_resource type="Resource" load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://lib/classes/state_animated_actor.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
resource_name = "idle"
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
debug_state = false
|
||||||
|
timeout_seconds = 2.0
|
||||||
|
name = "idle"
|
||||||
|
move_speed = 60.0
|
||||||
|
move_acceleration = 0.0
|
||||||
|
move_speed_modifier = 0.0
|
||||||
|
move_modifier_move_acceleration = 0.0
|
||||||
|
jerk_factor = 0.0
|
||||||
|
animation_sequence = [ "idle" ]
|
||||||
|
emitter_frame_subscriptions = {
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user