So, I'm making a coin generator that only generates coins inside a CollisionShape2D, I'm using preload() to load the coins and then add them in the scene and a Timer so it will generate coins every 10 seconds. I have a problem with the code, cause each 10 seconds when the node generates coins it causes FPS drops.
This is how the code looks:
$Timer.connect("timeout", self, "_checkGenerate")
for i in amount:
var cnd = preload("res://objects/candy.tscn")#I tried to put this line and the one below in _ready so it will do use the preload just one time, but stills causing FPS drops
var cn = cnd.instance()
var dk = $CollisionShape2D.shape.extents
cn.position = Vector2(randi()%(int(dk.x)*2)-int(dk.x), randi()%(int(dk.y)*2)-int(dk.y))
There's a better method that doesn't cause FPS drops?