Since your enemies are destroyed and don't respawn instantly, you need a different object to spawn them using a timer.
I implemented this minimal working example, in which every time an enemy is destroyed it notifies an object
objSpawnManager, that will choose a random spot and create a new enemy there.
Every spawn point is identified by an instance of
objSpawn, and the only thing it does is, well... exist. We place as many spawn as we want, because we want to recover their
y position when we'll need them later. Spawn locations are stored in a List data structure in
When an enemy is hit (I simulated hit with a simple mouse click for simplicity) it destroys itself, then increments the value of variable
queue of the
objSpawnManager. This variable tells the
objSpawnManager how many enemies are waiting for respawn yet.
objSpawnManager is in charge of the spawning system. Its variable
spawnTime is the number of seconds for spawning a new enemy;
spawnPoints is a DS List containing all
This is how it works:
Step Event: the manager checks if there are enemies waiting for respawn (
queue>0); if so, it starts the alarm countdown if it isn't counting down already (
!(alarm>=0), "alarm not working").
Alarm 0 Event: get the
id of a random spawn point from the DS List, then create a new enemy at such spawn location, finally decrease the value of
And that's it. The rest of the code just sets up some variables, and takes care of freeing memory when objects aren't needed anymore.