Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Robster | |
Old Version | Published before Godot 3 was released. |
Hi I know this must have been asked but I can’t find what I’m looking for so reluctantly asking. I have the following.
A scene with:
| board (2d node) as root
| - pieces (2d node) that sits inside board
At top of script:
var location = preload("res://location.tscn")
The above is just a 2d node with a sprite as a child
Then in my function below:
func setup_board():
for x in range(boardWidth):
var locationNode = location.instance()
get_node('pieces').add_child(locationNode)
I want to be able to then set the position of the most recently created locationNode
before I loop again and create the next one.
As you can see it’s been placed as a child of the 2DNode called pieces
. It’s in a loop, so in my example boardWidth
= 5 and it will create 5 of them, with the following names:
location
@location@2
@location@3
@location@4
@location@5
I tried various things and have been searching for some time but I keep getting errors. Does anyone know a way to set the location of the last added instance?
Thanks a tonne… Rob