Book Image

Cocos2d Game Development Blueprints

By : Jorge Jordán
Book Image

Cocos2d Game Development Blueprints

By: Jorge Jordán

Overview of this book

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

2-star challenge – adding pinecones to the scene


Now that we know how to create a varied (not random) terrain, I propose you use the knowledge acquired in this chapter to add pinecones to the game so they appear in a varied way in the scene.

For this purpose, you will find the JumpAndRunAtlas/pinecone.png image in the atlas to load these objects.

The solution

To accomplish this challenge, we will need to make a few changes to GameScene.m. First of all, declare an array of pinecones so we can handle them easily:

    // Declare array of pinecones
    NSMutableArray *_arrayOfPinecones;

Initialize this array by adding the following lines at the end of configureInitialScene:

    // Initialize pinecones' array with capacity
    _arrayOfPinecones = [NSMutableArray arrayWithCapacity:NUM_FLOORS * NUM_PLATFORMS];

We have initialized the array with the capacity of the maximum number of platforms that will be in the scene.

The next step is loading pinecones when a condition (that will be specified later) is...