Reputation: 79
So I basically create 5 instances of a KinematicBody2D. After that I set the position of each instance to a specific spawn point (I mean the first instance goes to the first spawnpoint, the second instance to the second spawnpoint, etc.). The problem is that the instances do not show up. I printed their location and each instance has the same coordinates with the spawnpoint that it should go to.
Here is my code:
extends Node2D
const block_scene = preload("res://Block.tscn")
const block_scene = preload("res://Block.tscn")
func _ready():
var i = 0
for i in 5:
var block = block_scene.instance()
block.position = spawnpoints.get_child(i).position
print(block.position)
Upvotes: 1
Views: 2332
Reputation: 20438
You also have to add the block
instances to the scene tree. If they should be children of your Node2D, you can call the add_child
method:
func _ready():
for i in range(5):
var block = block_scene.instance()
block.position = spawnpoints.get_child(i).position
add_child(block)
Upvotes: 2