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.
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 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.