Adding a destroy method to objects

No worries! It might be useful to you then. Here's an example from the forum:

Googling 'object pool in lua' gives you helpful links as well.

There's two central ideas in object pooling I think.

  • when you need an object like an enemy or bullet, you either create it in the pool if there's none free, or you get a free one from the pool. This means you do have to know if an object is active (in the game) or free to be reused from pool 'inactive'. Typically just a boolean flag on the object itself. The Lua objects stay in the pool, they just flip between active and free/inactive as your game plays.

  • when your game launches it's common to precreate objects to fill the pools. This also saves the processing time of having to create objects while your game is playing. The Play.Date is a great console but the it's built around a low power microprocessor :slight_smile:

This pattern is also super helpful for asset loading on the Play.Date and here's a great class for that: Best practices for managing lots of assets because you just want to load assets once (music, bitmaps, fonts etc) and reuse them many times thats also an object pool.

I agree for a quick prototype I maybe wouldn't set up pools first, but I think they're very helpful for anything you get to a publishable state. Lua garbage collection is expensive time wise and harder to control when it occurs.