Creating buttons

Buttons in one form or another are used in most games. It is easy to implement a simple button solution using Cocos2d but creating one that supports multiple simultaneous button touches is more difficult. In this recipe, we will implement a simple but effective solution to this problem.

Creating buttons

Getting ready

Please refer to the project RecipeCollection01 for full working code of this recipe.

How to do it...

Execute the following code:

//TouchableSprite.h @interface TouchableSprite : CCSprite { @public bool pressed; //Is this sprite pressed NSUInteger touchHash; //Used to identify individual touches } @end @implementation TouchableSprite ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.