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

Moving the zombie


Now that the game pad is working, it's time to use the touch events received to move our zombie. In this section we're just going to change its position on the screen, but in further sections we will animate it so it looks like the real living dead.

What we need to do to achieve this is implement the GamePadDelegate protocol as per our will. So in GameScene.h, find the following line:

@interface GameScene : CCScene {

Replace it with this one:

@interface GameScene : CCScene <GamePadDelegate>{

In GameScene.m, add the following lines at the end of the init method, just before return self;:

    // Set GameScene as the GamePad delegate
    _gamePad.delegate = self;

This will convert our scene class into a delegate of the protocol so we can implement the protocol methods. For the moment, we're just going to implement didChangeDirectionTo and isHoldingDirection, so add the following lines to GameScene.m:

- (void)gamePad:(GamePad *)gamePad didChangeDirectionTo:(GamePadDirections...