views:

42

answers:

0

I am writing an app for the iPhone using cocos2d where I have 4 Sprites that are buttons. I figured I would implement the button functionality by using 2 sprites with different .png files representing the pressed/unpressed states. I thought this would be better than using an animation. In addition to detecting when the buttons are pressed and released I need to detect when a two-button combination press/release occurs (like a chord). I might even carry this forward to 3 and 4 button combos. And one more feature I would like to implement would be detecting if a flick originated from within a button and respond with another action sequence.

What would be an optimal approach for this? Would I use a bounding rect/or sprite for the four buttons (they are in a square formation) and swallow touches? Then would I use the smaller sprite rects to determine which one(s) the touch(es) happened on? Or would I have the individual sprite rects do the detection and then have them check to see if the other buttons are also pressed and then released at the same time? Would I use a Bool state variable for either of these ways?

I had it all working great using CCMenu and CCMenuitem, by making one Menu/Menu-item for each button sprite; however, I could not figure out how to detect if a menu-item from one menu was pressed and released at the same time a menu-item from a different menu was pressed and released. I used separate menus because if I used the same menu with multiple menu-items then only one could be pressed at a time. I say it was working fine meaning it worked with single and multiple presses but it would treat multiples as two successive presses instead of a simultaneous press. IE: a single press resulted in running a single action sequence(as intended), and a simultaneous press combination resulted in running individual button action sequences for each button as if I had pressed them each separately(I want it to run one action sequence specific to that button combination). This is why I decided it might be better to try to implement my own button system instead of using the CCMenu system. Am I right in moving away from CCMenu?

Sorry for the long description, but it did say to be specific. B)

Any insight as to how anyone else implemented or would implement this would be greatly appreciated!