Hey everyone, today we talk about Pooling. Object pooling is a way to optimize your game that you should be using right now regardless of what game engine you’re using. Now, you might be wondering what Object Pooling is. Don’t worry, I’ll give you the details right now.
Object Pooling Concept
Let’s say you’re making your first bullet hell game. You’re firing bullets in every direction. Your player pew pews the enemies. Awesome!! But, then suddenly the game starts lagging. Why? Well, because the bullets you spawn never disappear from the game. So, every time you fire, the game is just adding more and more stuff to the PC memory, slowing down the game.
Object pooling is the solution to that problem. Object pooling is when you take the objects like the bullets that you spawn and reuse them rather than creating more. This saves space, optimizes memory and more.
So, how do we achieve this in HaxeFlixel? The actual code is straight-forward. Here’s how you setup pooling in HaxeFlixel!
As you can see all we do is cap the amount of elements that are in the group. Additionally, all you need to do to spawn objects is to use the recycle method above. Bam!! That’s pooling in HaxeFlixel.
For a live example, you can find it here. Play around with the size and see what happens!
With that said, I hope the post was helpful! Enjoy and good luck game making!! Stay tuned next time where we will get into more awesome tools in HaxeFlixel!