Sure, that can be done.
I might recommend something like:
- Create a standalone scene containing the
Area2D and anything else you want to be a part of your spawned instances.
- In a script on some controlling scene, preload your
Area2D scene using something like
var area2d = preload("res://Scenes/Area2D.tscn")
- Create a loop that will spawn as many instances as you want. You could use something like this to drive the loop
for i in range(10): (that'll execute the code in the loop 10 times)
- In the loop, create a new instance of your preloaded scene using
var newArea = area2d.instance()
- Also in the loop, position the newly instanced scene at some random location based on logic of your choice. With your new, random x and y position selected, you can place the new item there using
newArea.postion = Vector2(newX, newY)
That's really about it. Just season to taste...