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

3-star challenge – hitting the air


Besides moving the zombie, we will need to allow him to punch his enemies, so we should add a button to the game pad to defend him.

For this purpose, add a new sprite and perform a few modifications in the GamePad and GameScene classes. You can use the button.png image file included in the texture atlas.

The solution

To achieve this challenge, first let's declare a new sprite for the button by adding the following lines in GamePad.h after CCSprite *padSprite;:

    // Declare a sprite to represent the button
    CCSprite *buttonSprite;

There is nothing special here, just a CCSprite declaration. Then we want another CGFloat property to store the new button radius, so add the next line in the properties section:

@property (assign, nonatomic) CGFloat buttonRadius;

As we need to initialize a new sprite, we should modify the initializer method. Replace the initWithRadius method declaration with the following line:

(GamePad *) initWithPadRadius:(CGFloat)padRadius buttonRadius...