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.
//TouchableSprite.h @interface TouchableSprite : CCSprite { @public bool pressed; //Is this sprite pressed NSUInteger touchHash; //Used to identify individual touches } @end @implementation TouchableSprite - (bool)checkTouchWithPoint:(CGPoint)point { if(pointIsInRect(point, [self rect])){ return YES; }else{ return NO; } } - (CGRect) rect { //We set our scale mod to make sprite easier to press. //This also lets us press 2 sprites with 1 touch if they are sufficiently close. float scaleMod = 1.5f; float w ...