Recycling actor pools? Advice...

ThreepwoodThreepwood Member Posts: 30
edited November -1 in Working with GS (Mac)
I get the concept that spawning in gameplay is bad. I understand that you want to do something like place 10 bad guys off screen at the start of a level and move them in from the pool as needed, and when killed, you just move them back offscreen to await rebirth.

What I don't really know how to do in GS is track the actors in the pool and know how to bring a specific one back. With a normal language you'd just have an array or something.

It's pretty easy to use a counter to know how may are on screen vs off, so you know if the pool has a free resource for a 'spawn'.

Do you use the tag system or something like that to indicate if an actor is available?

Comments

  • ThreepwoodThreepwood Member Posts: 30
    So let's say I kill a zombie and it dies, and flashes and goes off screen. How do I bring that specific actor back on screen at some arbitrary time/rule in the future? It may be off screen from 1-20 seconds.

    Say you are shooting bullets and can have maybe 3 on screen at a time (before they hit the edges and disappear and get reallocated). How do you go about cycling through the 3 shot pool in the best way, knowing which bullet actor is free off screen?
  • specialist_3specialist_3 Member Posts: 121
    Threepwood,

    refer to http://gamesalad.com/forums/topic.php?id=9710

    search for VictorKin11's demo on recycle bullets on shared projects. he recycles 5 bullets over and over again.
  • ThreepwoodThreepwood Member Posts: 30
    I figured it out. Thanks. It is a fair bit of work. You need to keep track of 1) if it's ok to spawn a new bullet (firing rates, etc) 2) if the bullet actor is already in use or not, 3) manage the off screen and constraining the x/y to whatever you like 4) making sure you have some fallback or debug if you want for failure to spawn (ie: you are firing too fast for the allotted pool you have).

    Even with the work I think I'd like to get to a virtually spawn free game. For an example I had 7 characters walking around, the player and shooting invisible, fast moving projectiles (bullets), and spawning blood particles when hit.

    The game started and stayed at 60fps for a couple of mins. I was tracking the spawns and destroys on screen and once you got over about 300, you'd start getting fps dips to 40 or lower. Dropping from 60fps to 40fps is not ok. Feels terrible and will never fly on older phones. Has to be memory fragmentation or something? It will be a day or work but it should be pretty trivial to reduce virtually 100% of the spawns and have it just load up on level init and then the fps *should* stay at 60.

    For any game that needs to spawn > 100 actors per scene you'll probably have a better game using recycled pools. Once you put a counter on screen you will be shocked how quickly you can approach 1000 spawn/destroys.
  • thegwillthegwill Member Posts: 31
    Why is spawning so bad?
    Does it leak memory or is it a performance concern?
  • firemaplegamesfiremaplegames Member Posts: 3,211
    @thegwill: Performance concern. If the Actor you spawn has a lot of Rules, you will notice a hiccup in the game when it spawns. Spawned Actors also add to the total RAM usage, which will eventually cause a crash if you go too far above 40MB in an Scene on older devices.
  • thegwillthegwill Member Posts: 31
    Ok thanks.
Sign In or Register to comment.