Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | vandalk | |
Old Version | Published before Godot 3 was released. |
Hello Everyone!
I’m creating a beat’em up game in Godot! I’m trying to test player controls and to do that I start the scene with 3 enemies, and spawn 3 more whenever all enemies are killed.
This is the code for my spawner:
extends Node2D
##########################
# Class Member Variables #
##########################
const ENEMY = preload("res://Enemies/Enemy01/Enemy01.tscn")
const MAX_ONSCREEN_ENEMIES = 4
onready var entities_layer = self.get_node("../EntitiesLayer")
onready var player = entities_layer.get_node("Player")
#############################
# Custom Method Definitions #
#############################
func spawn_enemies():
var children = entities_layer.get_child_count()
if children < 2:
var to_spawn = MAX_ONSCREEN_ENEMIES-children
for n in range(to_spawn):
var enemy = ENEMY.instance(true)
var posx = player.get_pos().x + floor(rand_range(-45,46))
var posy = player.get_pos().y + floor(rand_range(-11,12))
enemy.set_pos(Vector2(posx,posy))
entities_layer.add_child(enemy)
pass
pass
###########################
# Engine Standard Methods #
###########################
func _ready():
randomize(true)
set_process(true)
pass
func _process(delta):
spawn_enemies()
pass
It works fine when I’m testing the game in the editor, but once I export it, the resulting executable doesn’t spawn anything, after I kill the first 3 enemies.
Is there something wrong on the code above? Is it some project settings? How can I try to debug the exported executable to try and find out what’s happening?
If you need more information about the project, or want to test it out in the editor yourself, you can find it here on github - GitHub - eh-jogos/Beatwo: A King Of The Hill beat'em up that uses only two buttons. Done with Godot.