freeing objects when then leave the screen

This commit is contained in:
Nabzzz 2021-04-12 11:40:02 +02:00
parent c1a1e9aadf
commit a84ceea08d
4 changed files with 24 additions and 4 deletions

View file

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

View file

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

View file

@ -1,6 +1,15 @@
extends "scroll_movement.gd"
onready var notifier = $notifier
func _ready():
get_node("notifier").connect("screen_exited", self, "_on_screen_exited")
func _on_screen_exited():
print("Bonus exited the screen")
queue_free()
func _physics_process(delta):
move()

View file

@ -1,12 +1,22 @@
extends "scroll_movement.gd"
onready var notifier = $notifier
func _ready():
get_node("notifier").connect("screen_exited", self, "_on_screen_exited")
func _on_screen_exited():
print("Obstacle exited the screen")
queue_free()
func _physics_process(delta):
move()
func _on_collision_obstacle_body_entered(body):
if body.name == "player2" :
Signals.emit_signal("die")
queue_free()