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.
Please refer to the project RecipeCollection01 for full working code of this recipe. Also, note that some code has been omitted for brevity.
#import "TouchableSprite.h" @interface DPad : TouchableSprite { @public CGPoint pressedVector; int direction; } @end @implementation DPad -(id)init { self = [super init]; if (self != nil) { pressedVector = ccp(0,0); direction = DPAD_NO_DIRECTION; CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache]; [cache addSpriteFramesWithFile:@"dpad_buttons.plist"]; //Set the sprite display frame [self setDisplayFrame:[cache spriteFrameByName:@"d_pad_normal.png"]]; } return self; } /* Process...