Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
LibGDX Game Development By Example

You're reading from   LibGDX Game Development By Example Learn how to create your very own game using the libGDX cross-platform framework

Arrow left icon
Product type Paperback
Published in Aug 2015
Publisher
ISBN-13 9781785281440
Length 280 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
James Cook James Cook
Author Profile Icon James Cook
James Cook
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Getting to Know LibGDX FREE CHAPTER 2. Let's Get These Snakes Out of This Book! 3. Making That Snake Slick 4. What the Flap Is the Hype About? 5. Making Your Bird More Flightworthy 6. Onto the Next Platform...Game 7. Extending the Platform 8. Why Are All the Birds Angry? 9. Even Angrier Birds! 10. Exporting Our Games to the Platforms 11. Third-party Services Index

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 own right. This class will implement the Pool.Poolable interface.

The following is the code listing for our new Acorn class:

public class Acorn implements Pool.Poolable {
  private final Sprite sprite;
  public Acorn(AssetManager assetManager) {
  ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime