GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Recycling actor pools? Advice...

ThreepwoodThreepwood Posts: 30Member
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 Posts: 30Member
    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 Posts: 121Member
    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 Posts: 30Member
    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 Posts: 31Member
    Why is spawning so bad?
    Does it leak memory or is it a performance concern?
  • firemaplegamesfiremaplegames Posts: 3,206Member
    @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 Posts: 31Member
    Ok thanks.
This discussion has been closed.