diff --git a/RockSpawner.gd b/RockSpawner.gd index 11b862d..8ee3373 100644 --- a/RockSpawner.gd +++ b/RockSpawner.gd @@ -15,7 +15,9 @@ func _spawn_rock(): func _set_rock_position(rock): var rect = get_viewport().size - rock.position = Vector2(rand_range(0, rect.x), -100) + #rock.position = Vector2(rand_range(0, rect.x), -100) + rock.position = Vector2(250, rand_range(-10, 400)) + # 250 so they spawn off screen, -10 to 400 so they spawn somewhere above or below the platy func _on_SpawnTimer_timeout(): diff --git a/RockSpawner.tscn b/RockSpawner.tscn index 0b863ee..90608b5 100644 --- a/RockSpawner.tscn +++ b/RockSpawner.tscn @@ -1,3 +1,12 @@ -[gd_scene format=2] +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://RockSpawner.gd" type="Script" id=1] [node name="RockSpawner" type="Node"] +script = ExtResource( 1 ) + +[node name="SpawnTimer" type="Timer" parent="."] +wait_time = 3.0 +autostart = true + +[connection signal="timeout" from="SpawnTimer" to="." method="_on_SpawnTimer_timeout"] diff --git a/rock1.gd b/rock1.gd new file mode 100644 index 0000000..2d7ffc3 --- /dev/null +++ b/rock1.gd @@ -0,0 +1,20 @@ +extends RigidBody2D + + +# 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 + + +func _on_VisibilityNotifier2D_viewport_exited(viewport): + queue_free() diff --git a/rock1.tscn b/rock1.tscn index be8b6ef..fe90247 100644 --- a/rock1.tscn +++ b/rock1.tscn @@ -1,14 +1,18 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://assets/textures/rock1.png" type="Texture" id=1] +[ext_resource path="res://rock1.gd" type="Script" id=2] [sub_resource type="CircleShape2D" id=1] radius = 32.0067 -[node name="rock1" type="RigidBody2D"] -position = Vector2( 258.349, 4.97968 ) +[node name="rock1" type="RigidBody2D" groups=[ +"rocks", +]] +position = Vector2( 262.839, -114.001 ) gravity_scale = 0.0 linear_velocity = Vector2( -100, 0 ) +script = ExtResource( 2 ) [node name="Sprite" type="Sprite" parent="."] position = Vector2( -6.89056, 239.487 ) @@ -18,3 +22,7 @@ texture = ExtResource( 1 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2( -6.61053, 238.888 ) shape = SubResource( 1 ) + +[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."] + +[connection signal="viewport_exited" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_viewport_exited"]