4.12 Connecting Signals Dynamically
This commit is contained in:
parent
91f71a39fd
commit
499b5c3546
6 changed files with 44 additions and 34 deletions
|
|
@ -23,6 +23,10 @@ window/size/window_width_override=1440
|
||||||
window/size/window_height_override=810
|
window/size/window_height_override=810
|
||||||
window/stretch/mode="canvas_items"
|
window/stretch/mode="canvas_items"
|
||||||
|
|
||||||
|
[global_group]
|
||||||
|
|
||||||
|
traps="some kind of trap that causes player to take damage in various ways"
|
||||||
|
|
||||||
[input]
|
[input]
|
||||||
|
|
||||||
move_left={
|
move_left={
|
||||||
|
|
|
||||||
|
|
@ -79,5 +79,3 @@ position = Vector2(272, 163)
|
||||||
position = Vector2(188, 113)
|
position = Vector2(188, 113)
|
||||||
|
|
||||||
[connection signal="body_entered" from="Deathzone" to="." method="_on_death_zone_body_entered"]
|
[connection signal="body_entered" from="Deathzone" to="." method="_on_death_zone_body_entered"]
|
||||||
[connection signal="touched_player" from="Traps/SawTrap" to="." method="_on_trap_touched_player"]
|
|
||||||
[connection signal="touched_player" from="Traps/SpikeBallTrap" to="." method="_on_trap_touched_player"]
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,21 @@
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_1ysy5"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_1ysy5"]
|
||||||
radius = 18.0
|
radius = 18.0
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_gqn61"]
|
||||||
|
length = 0.001
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("Area2D/Sprite2D:frame")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 1,
|
||||||
|
"values": [0]
|
||||||
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_0uemr"]
|
[sub_resource type="Animation" id="Animation_0uemr"]
|
||||||
resource_name = "spin"
|
resource_name = "spin"
|
||||||
length = 0.400005
|
length = 0.400005
|
||||||
|
|
@ -24,28 +39,13 @@ tracks/0/keys = {
|
||||||
"values": [0, 1, 2, 3, 4, 5, 6, 7]
|
"values": [0, 1, 2, 3, 4, 5, 6, 7]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_gqn61"]
|
|
||||||
length = 0.001
|
|
||||||
tracks/0/type = "value"
|
|
||||||
tracks/0/imported = false
|
|
||||||
tracks/0/enabled = true
|
|
||||||
tracks/0/path = NodePath("Area2D/Sprite2D:frame")
|
|
||||||
tracks/0/interp = 1
|
|
||||||
tracks/0/loop_wrap = true
|
|
||||||
tracks/0/keys = {
|
|
||||||
"times": PackedFloat32Array(0),
|
|
||||||
"transitions": PackedFloat32Array(1),
|
|
||||||
"update": 1,
|
|
||||||
"values": [0]
|
|
||||||
}
|
|
||||||
|
|
||||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_q37r8"]
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_q37r8"]
|
||||||
_data = {
|
_data = {
|
||||||
"RESET": SubResource("Animation_gqn61"),
|
"RESET": SubResource("Animation_gqn61"),
|
||||||
"spin": SubResource("Animation_0uemr")
|
"spin": SubResource("Animation_0uemr")
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="SawTrap" type="Node2D"]
|
[node name="SawTrap" type="Node2D" groups=["traps"]]
|
||||||
script = ExtResource("1_23awk")
|
script = ExtResource("1_23awk")
|
||||||
|
|
||||||
[node name="Area2D" type="Area2D" parent="."]
|
[node name="Area2D" type="Area2D" parent="."]
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,21 @@
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_1ysy5"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_1ysy5"]
|
||||||
radius = 11.0
|
radius = 11.0
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id="Animation_7h84l"]
|
||||||
|
length = 0.001
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/imported = false
|
||||||
|
tracks/0/enabled = true
|
||||||
|
tracks/0/path = NodePath("Area2D:position")
|
||||||
|
tracks/0/interp = 1
|
||||||
|
tracks/0/loop_wrap = true
|
||||||
|
tracks/0/keys = {
|
||||||
|
"times": PackedFloat32Array(0),
|
||||||
|
"transitions": PackedFloat32Array(1),
|
||||||
|
"update": 0,
|
||||||
|
"values": [Vector2(0, 0)]
|
||||||
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_qms3f"]
|
[sub_resource type="Animation" id="Animation_qms3f"]
|
||||||
resource_name = "move"
|
resource_name = "move"
|
||||||
length = 2.0
|
length = 2.0
|
||||||
|
|
@ -23,28 +38,13 @@ tracks/0/keys = {
|
||||||
"values": [Vector2(0, 0), Vector2(100, 0)]
|
"values": [Vector2(0, 0), Vector2(100, 0)]
|
||||||
}
|
}
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_7h84l"]
|
|
||||||
length = 0.001
|
|
||||||
tracks/0/type = "value"
|
|
||||||
tracks/0/imported = false
|
|
||||||
tracks/0/enabled = true
|
|
||||||
tracks/0/path = NodePath("Area2D:position")
|
|
||||||
tracks/0/interp = 1
|
|
||||||
tracks/0/loop_wrap = true
|
|
||||||
tracks/0/keys = {
|
|
||||||
"times": PackedFloat32Array(0),
|
|
||||||
"transitions": PackedFloat32Array(1),
|
|
||||||
"update": 0,
|
|
||||||
"values": [Vector2(0, 0)]
|
|
||||||
}
|
|
||||||
|
|
||||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_14ytm"]
|
[sub_resource type="AnimationLibrary" id="AnimationLibrary_14ytm"]
|
||||||
_data = {
|
_data = {
|
||||||
"RESET": SubResource("Animation_7h84l"),
|
"RESET": SubResource("Animation_7h84l"),
|
||||||
"move": SubResource("Animation_qms3f")
|
"move": SubResource("Animation_qms3f")
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="SpikeBallTrap" type="Node2D"]
|
[node name="SpikeBallTrap" type="Node2D" groups=["traps"]]
|
||||||
script = ExtResource("1_x0eb1")
|
script = ExtResource("1_x0eb1")
|
||||||
|
|
||||||
[node name="Area2D" type="Area2D" parent="."]
|
[node name="Area2D" type="Area2D" parent="."]
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,13 @@ extends Node2D
|
||||||
@onready var player: CharacterBody2D = $Player
|
@onready var player: CharacterBody2D = $Player
|
||||||
@onready var start_position: Marker2D = $StartPosition
|
@onready var start_position: Marker2D = $StartPosition
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
var traps = get_tree().get_nodes_in_group("traps")
|
||||||
|
|
||||||
|
for trap in traps:
|
||||||
|
if trap is Trap:
|
||||||
|
trap.touched_player.connect(_on_trap_touched_player)
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
class_name Trap
|
||||||
|
|
||||||
signal touched_player
|
signal touched_player
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue