Book Image

Cocos2d-X Game Development Blueprints

By : Karan Sequeira
Book Image

Cocos2d-X Game Development Blueprints

By: Karan Sequeira

Overview of this book

Table of Contents (17 chapters)
Cocos2d-x Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating and reusing collectibles


While creating games, sometimes you may come across some of your game elements repeating themselves over and over as the level progresses. Consider you have a side-scrolling platform where your character is supposed to collect things such as coins, stars, health packs, and so on. Now, you might want to create these elements just before they enter the screen and delete them when the character collects them or when they exit the screen. However, this may not be the most efficient approach.

So, I will show you a commonly used technique of pooling or caching your game's elements so that they can be reused. What this means is that you will create a predefined maximum number of elements and place them in a container when the game or level loads. When required, elements will be removed from this container and merely added to the game world. Conversely, after their task is finished, they will be removed from the game world and added back to the container. This way...