O'Reilly logo

LibGDX Game Development By Example by James Cook

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hey, look at all these acorns!

Now we have a handle on what an object pool is, why we need one, and how we can use LibGDX to look after one for us. Next, we need to look at how we can use one in Nutty Birds.

I am going to take a liberty with the gameplay and make a fundamental change to the way the game is played. We will design the game in such a way that we can only have three acorns on the screen at on time. Whenever you fire another while three are already in play, the oldest will be removed from the game. This may sound rather crude, but our aim here is to try out an object pool. Once we are done, you can try and shape the game the way you wish to.

Pooling the acorns

Our first task is to move our acorn from a Sprite instance to a class in its ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required