Browse Source

freeing objects when then leave the screen

Nabzzz 6 months ago
parent
commit
a84ceea08d

+ 2
- 3
mini-game/scenes/bonuses/bonus1.tscn View File

@@ -4,9 +4,6 @@
4 4
 [ext_resource path="res://mini-game/ressources/sprites/bonus/bone.png" type="Texture" id=2]
5 5
 [ext_resource path="res://mini-game/scenes/effets/pick_bonus.tscn" type="PackedScene" id=3]
6 6
 
7
-
8
-
9
-
10 7
 [sub_resource type="RectangleShape2D" id=1]
11 8
 extents = Vector2( 24.0183, 9.31512 )
12 9
 
@@ -21,4 +18,6 @@ texture = ExtResource( 2 )
21 18
 
22 19
 [node name="CollisionShape2D" type="CollisionShape2D" parent="pick_bonus"]
23 20
 shape = SubResource( 1 )
21
+
22
+[node name="notifier" type="VisibilityNotifier2D" parent="."]
24 23
 [connection signal="body_entered" from="pick_bonus" to="." method="_on_pick_bonus_body_entered"]

+ 2
- 0
mini-game/scenes/obstacles/obstacle1.tscn View File

@@ -18,4 +18,6 @@ texture = ExtResource( 2 )
18 18
 
19 19
 [node name="CollisionShape2D" type="CollisionShape2D" parent="collision_obstacle"]
20 20
 shape = SubResource( 1 )
21
+
22
+[node name="notifier" type="VisibilityNotifier2D" parent="."]
21 23
 [connection signal="body_entered" from="collision_obstacle" to="." method="_on_collision_obstacle_body_entered"]

+ 9
- 0
mini-game/scripts/bonus1.gd View File

@@ -1,6 +1,15 @@
1 1
 extends "scroll_movement.gd"
2 2
 
3 3
 
4
+onready var notifier = $notifier
5
+
6
+func _ready():
7
+	get_node("notifier").connect("screen_exited", self, "_on_screen_exited")
8
+
9
+func _on_screen_exited():
10
+	print("Bonus exited the screen")
11
+	queue_free()
12
+
4 13
 func _physics_process(delta):
5 14
 	move()
6 15
 	

+ 11
- 1
mini-game/scripts/obstacle1.gd View File

@@ -1,12 +1,22 @@
1 1
 extends "scroll_movement.gd"
2 2
 
3 3
 
4
+
5
+onready var notifier = $notifier
6
+
7
+func _ready():
8
+	get_node("notifier").connect("screen_exited", self, "_on_screen_exited")
9
+
10
+func _on_screen_exited():
11
+	print("Obstacle exited the screen")
12
+	queue_free()
13
+
4 14
 func _physics_process(delta):
5 15
 	move()
6
-	
7 16
 
8 17
 
9 18
 func _on_collision_obstacle_body_entered(body):
10 19
 	if body.name == "player2" : 
11 20
 		Signals.emit_signal("die")
12 21
 		queue_free()
22
+

Loading…
Cancel
Save