Browse Source

:wrench: Kill the ball when exiting screen

DricomDragon 2 years ago
parent
commit
f5f3a511b6
3 changed files with 25 additions and 2 deletions
  1. 10 0
      labs/cascade/component/ball/Ball.gd
  2. 9 2
      labs/cascade/component/ball/Ball.tscn
  3. 6 0
      project.godot

+ 10 - 0
labs/cascade/component/ball/Ball.gd

@@ -0,0 +1,10 @@
+class_name Ball
+extends RigidBody2D
+
+
+func die():
+	queue_free()
+
+
+func _on_VisibilityNotifier2D_screen_exited():
+	die()

+ 9 - 2
labs/cascade/component/ball/Ball.tscn

@@ -1,15 +1,18 @@
-[gd_scene load_steps=4 format=2]
+[gd_scene load_steps=5 format=2]
 
 [ext_resource path="res://labs/cascade/component/ball/firefox-logo.png" type="Texture" id=1]
+[ext_resource path="res://labs/cascade/component/ball/Ball.gd" type="Script" id=2]
 
 [sub_resource type="PhysicsMaterial" id=2]
-bounce = 0.22
+friction = 0.61
+bounce = 0.26
 
 [sub_resource type="CircleShape2D" id=1]
 radius = 4.0
 
 [node name="Ball" type="RigidBody2D"]
 physics_material_override = SubResource( 2 )
+script = ExtResource( 2 )
 
 [node name="FirefoxSprite" type="Sprite" parent="."]
 scale = Vector2( 0.064, 0.064 )
@@ -17,3 +20,7 @@ texture = ExtResource( 1 )
 
 [node name="RoundFixture" type="CollisionShape2D" parent="."]
 shape = SubResource( 1 )
+
+[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]
+
+[connection signal="screen_exited" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_screen_exited"]

+ 6 - 0
project.godot

@@ -9,6 +9,11 @@
 config_version=4
 
 _global_script_classes=[ {
+"base": "RigidBody2D",
+"class": "Ball",
+"language": "GDScript",
+"path": "res://labs/cascade/component/ball/Ball.gd"
+}, {
 "base": "Button",
 "class": "SelectButton",
 "language": "GDScript",
@@ -20,6 +25,7 @@ _global_script_classes=[ {
 "path": "res://menu/button/start/StartButton.gd"
 } ]
 _global_script_class_icons={
+"Ball": "",
 "SelectButton": "",
 "StartButton": ""
 }