Jump to content


Some Old Door

Member Since 02 Aug 2007
Offline Last Active Apr 14 2013 06:26 AM

Topics I've Started

Spawning waves of enemies using objects

15 July 2010 - 05:05 PM

Hi there! I'm having a problem in my game--

I am making a side-scrolling shooting game. In my game, at various points in the timeline I will create an object called "enemyspawner". This object sits out of the current view on the right hand side of the screen and scrolls along with the level, remaining unseen. At the point that the enemyspawner is created, it is also passed a few variables in order for it to create a set amount of enemies. These variables are:

- steps inbetween making next enemy ship
- type of enemy ship
- location to spawn enemy ship
- number of ships to make before self-destructing
- path for the enemy ship to follow

At the moment, this works fine, I can tell an enemyspawner to make 10 enemies 30 frames apart at a y-height of 180. After it has done this, it will destroy itself. Perfect! However I have noticed a pretty big problem with how this works in my code.

Say I want to make two waves of enemies simultaneously, one at y=100 and another at y=200. When I do this, both of the enemyspawners are created, but for some reason they always get created in the same spot, even if the x and y are different in the instance_create! Additionally, the path for the enemy to follow is always the same as the enemyspawner that was created first, even if the second one has a different variable for that. I'm wondering if this has something to do with instances, and that somehow whenever I create an enemyspawner I am inadvertently passing the variables for the enemyspawner out to all enemyspawners instead of a specific one, but I don't think that is possible since I am passing the variables to the exact id by storing it in a local var when I do the instance_create for the enemyspawner. Furthermore, it doesn't make sense to me that the enemyspawner created second should somehow mimic the behaviours of one that was created before it, seems more likely that it would be the other way around.

I don't have the GML on hand at the moment, but I can post it up if that would help.

Lastly, can anyone tell me is this is a super-dumb way of spawning enemy ships in waves a certain distance apart? It seems a bit elaborate to make an object to make other objects when I could just make the objects directly, but I don't want to have to put 10 entries into a timeline when I can just make one enemyspawner with a few variables that effectively does this for me.

I had another idea that maybe I could spawn all the ships simultaneously without using a spawner object, and just separate them out in a for loop using distance by incrementing the original spawn x+=i*spawn_delay (in a for loop), but then if I ever wanted to change the scrolling direction or speed the distances during a wave they would be all out of whack. Also, it would be hard to get this to work for enemies that come up behind you.

Sorry if this is a little long-winded, but this one is keeping me up at night!