How do I create a good spawn-system?

0 favourites
  • 5 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • Hello!

    I'm trying to create a tower defence game. But im stuck on how I should spawn the enemys in a good way. At the moment im just creating a random enemy every X second and X decreases after every wave. But I want to have more controll of what type of enemy and how many for every wave. If I were to create a event like level=1 & wave=1 for every level there whould be a very long eventsheet wich i dont mind but will it kill performance? Any tips are apreaciated.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • DetteMan, I am working with something like this in my autorunner game. I have thought out several ways to do this, and this is what we went with.

    For each spawnable item, I store a spawn weight. Each time an item is about to be spawned, a random number score is picked for each item between 0 and that item's spawn weight. The item with the highest randomly picked number score is the one that is spawned. Throughout the game, each level of my game raises or lowers the spawn weight of each item, effectively controlling the probability of the item winning a spawn choice. I store all the spawn weights, and the changes to spawn weight for each level in JSON and dictionaries.

    None of the spawning code has to change for each level, only the spawn weights. I can dynamically turn off an item by giving it a spawn weight of 0, or make an item more likely to spawn by giving it a higher weight than another item.

    You could also store for each level the number of enemies to generate and just keep a counter as they spawn to figure out when to move to the next level, and load the next set of weights and values from JSON.

  • Hey DetteMan, performance wise, there a few tips that you can learn and test if you want i can share with u some of my fixes to gain some extra fps on your games, as for spawning system depends ... not sure what kind of info you wold like, there is a lot of things to talk about, depends mostly what you are aiming for in the end.. maybe share a capx for understanding what your doing...

    so some.... few tips for for those FPS gains :

    1 if you have alot of spawns in at a time wold problebly create cold zones for you mobile games as for computers u dont have to worrie about it to much, avoid doing them every x second as much as possible or increase the time frame between spawns, like on wave1 you wold want instead of spawning all mobs in 1 shot try using a bolean or a count down every 0.5 seconds creates a mob outside screen that follows the path ... when the count down is finish set the wave 2 ready but start it 1 second later then repeat,

    if you are having allot of text objects, avoid updating them every tick or every less then "every 0.5s" try using the "text " to update when some action happens, as in when mob 1 gets killed , set text to value of score + value of mob kill don't do the math on a "every tick" and then just update the "text object" that will decrease your fps rate by 3-5, at least, for each text object, avoid as much possible ( "every tick" can mean also when something is true as: sometimes you may create a condition that will be all the time met by the system so that will be called "every tick" as well).

    so you better understand the every tick system is not only the every tick you have from c2 system , its also automatically the condition you can create and leave it open as in is a mob on screen? is a level 1 started? is score >number or is score less <number that automatically by C2 acts like everytick (that is tryng to do what ever your action is at 1 milisecond or less) so imagine if u have 10 mobs spawning at a time and give them to all the same action , 1st the game will dramatically suffer fps los, and 2 u might get freezing screens on mobile, as for pc they can slow a bit depends what crappy pc people have , me personally i dident change my Hardware in 10 years, did not needed to, i`m thinking to rebuild a new one :-s just are so many choices...

    hope you got the point of fps gaining, if u arent already aware of it now you should know what to avoid, and how, as long with ur system for spawning mhmm... not sure dident made any tower defense games , i playd a bit with some engines but they where using cubes and simple shapes, so im guessing u have some animations, and other things, try reducing them also or compress the shit out of them there are alot of png compressors out for free as tinypng and many others, if u dont use a png try making the frames bordered with black not white , and use alpha chanel but then ul need webgl support so most of mobiles doesnt handle that good.

    for spawning i wold say to create a count down that creates 1 mob every second and u can have like 3 types of mobs , little medium strong, lets say, every category has 10 ammo clips like bullets, right? so each wave ul have 30 enemys to kill in game, now in order to spawn them random or in order u need to create 6 variables 3 for the categorys 3 for the mobs in the category 1 for the countdown, the variables for the categorys can be numbers ,text , or bolean, if its a number u use , u can set when number is 1 on category 1 spawn every 1.5 seconds until enemy > or equal to 0 , never say equal because the system may sometimes spawn 2 enemys at 1 time, so when that category amo number is empty move to next category and repeat it till all mobs are spawn, you may want to add a speed button so the mobs are spawned faster, and move faster, since its upgrade&autokill type of game. it takes longer, to create a speed button, u need 3 buttons or 2 or more depends how many stages of speed u want to add, and the system event timescale if its 0 game stops if its 1 game speed is normal anything above 1 will increase the game speed. so kinda those are my tips for you, hope it helped.

  • p.s you may also want to take in consideration the usage of trigger once while true condition , that will avoid creating multiple mobs in same spot and when u kill you will see double score,

  • Thanks for very detailed and good answers. I have decided though to go with groups that i set active and deactive depending on level and wave. That way i can specify how easy wave will be.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)