O'Reilly logo

Cocos2d for iPhone 1 Game Development Cookbook by Nathan Burba

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required