Hiya! I have a problem instancing "enemies" for my platformer.
I have a scene for the level and another scene for the enemy (which is a KinematicBody2D); I'm trying to use a Path2D to spawn several enemies. Here's the code:
extends Node2D
signal restarting
export (PackedScene) var Enemy
export (int) var total_enemies = 0
# Called when the node enters the scene tree for the first time.
func _ready():
var pos_curve = $EnemyPositions.get_curve()
total_enemies = pos_curve.get_point_count()
for i in range(0, total_enemies):
var enemy = Enemy.instance()
add_child(enemy)
enemy.position = pos_curve.get_point_position(i)
enemy.startPositionX = enemy.position.x
enemy.startPositionY = enemy.position.y
enemy.directedToRight = true
When I run the code, I receive the message in the title, referred to this line:
var enemy = Enemy.instance()
What's the problem?
Thanks in advance!