Creating a directional pad

Another fundamental form of video game input is the directional pad. In this recipe, you will see how to create a convincing 3D-ish directional pad and you will see how to properly process directional pad information in a game situation.

Creating a directional pad

Getting ready

Please refer to the project RecipeCollection01 for full working code of this recipe. Also, note that some code has been omitted for brevity.

How to do it...

Execute the following code:

#import "TouchableSprite.h" @interface DPad : TouchableSprite { @public CGPoint pressedVector; int direction; } @end @implementation DPad -(id)init { self = [super init]; if (self != nil) { pressedVector ...

Get Cocos2d for iPhone 1 Game Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.