I am coding a star collect game in Godot, but while trying to add a scene as a child of the main (The scene which starts first, and the scene where I am doing the instancing), it's not working, rather the debug screen lags so much that it shows "Not Responding". I am coding in GDScript. Here's what I coded in the main scene to do the instancing:
extends Node2D
export (PackedScene) var Star
func _ready():
pass
func _on_Timer_timeout():
var star = Star.instance()
add_child(star)
I've also inserted the desired scene I want to instance in the Script variables section (Sorry, as I'm new to Godot I'm not able to explain the terms well) : Script Variables section
And this is the code of the scene which I am instancing:
extends Area2D
export var done = 0
export var speed = 43
export var spinVal = 0
export var dir = 0
func _ready():
done=0
dir=5-(randf()*10)
spinVal = 5-(randf()*10)
position.x=randf()*10
position.y=-20
while done==0:
position.y+=speed
rotation_degrees=0+dir
rotate(spinVal)
print(position)
func _on_VisibilityNotifier2D_screen_exited():
if (position.y<720):
done=1
queue_free()
Before, I had tried the simple way of instancing before I used PackedScene method, but I was facing the same problem. Now I'm trying it this way but no improvements...