Mike Laurence's Blog RSS

Archive

Mar
29th
Thu
permalink

Cocos2d macro hackery for Mac/iOS app input

Deepworld handles both iOS and Mac via the same Cocos2D XCode project. All it takes is a little target differentiation and some compilation-time conditional logic

And a bunch of headaches. And time.

Naturally, the main difference is input style: touch-based on iOS, mouse- and keyboard-based on the Mac. It’s often important to design input mechanisms separately for each style, as touch input in particular can offer unique depth (e.g., with gestures). However, there are still many cases where you can share interface behavior. In particular, menus, buttons, and other clickable/tappable things act more or less the same.

Cocos2D offers ccMouseDown (and its related methods) for Mac and ccTouchBegan for iOS. When you don’t care about differentiating, well, you might as well use a little macro magic to keep your code tight. We’ve done this in Deepworld with the following: