- #1
Darkmisc
- 220
- 31
- TL;DR Summary
- I'm just starting to learn GDScript. I'd like an object to spawn near the top of the viewport, move towards the bottom, disappear and then spawn again. I can only get it to spawn once.
Hi everyone
I'd like to spawn an object at the top of the screen, have the object move towards the bottom, disappear and then spawn again at the top of the screen (to repeat the cycle). I've used the below code.
When I run it, the object spawns once, moves towards the bottom, disappears and that's it. It doesn't spawn again.
Does anyone know what I've done wrong?Thanks
I'd like to spawn an object at the top of the screen, have the object move towards the bottom, disappear and then spawn again at the top of the screen (to repeat the cycle). I've used the below code.
When I run it, the object spawns once, moves towards the bottom, disappears and that's it. It doesn't spawn again.
Does anyone know what I've done wrong?Thanks
gameplay:
extends Node2D
var plsquare = preload("res://MainScenes/square/square.tscn")func _ready():
var square = plsquare.instance()
get_tree().current_scene.add_child(square)
square.position = Vector2(-200, rand_range(0, 100))
if square.position.y>199:
square = plsquare.instance()
get_tree().current_scene.add_child(square)
square.position = Vector2(-200, rand_range(0, 100))
square:
extends Area2Dexport var speed: float = 100
var vel:=Vector2(0,0)
func _process(delta):
pass
func _physics_process(delta):
vel.y=speed
position +=vel * delta
if position.y>200:
queue_free()