Game Development Reference
In-Depth Information
Kobold2D therefore supports locale-independent keyboard input based on key codes.
You can check whether the D key was pressed in Kobold2D like this:
[[KKInput sharedInput] isKeyDownThisFrame:KKKeyCode_D];
This works independently of whether the user has had the Shift key pressed or not. To
include the Shift key in the check, simply write:
KKInput* input = [KKInput sharedInput];
[input isKeyDownThisFrame:KKKeyCode_D modifierFlags:KKModifierShiftKeyMask];
Kobold2D users don't need to delve further into this subject because Kobold2D already
provides solid, documented keyboard and mouse input implementation:
www.kobold2d.com/display/KKDOC/Processing + User+Input . But
cocos2d users can learn more about keyboard event handling in this forum thread:
www.cocos2d-iphone.org/forum/topic/11725 . Apple's documentation on
handling key events is also very helpful: http://developer.apple.com/lib-
rary/mac/#documentation/cocoa/conceptual/EventOverview/
HandlingKeyEvents/HandlingKeyEvents.html .
Receiving Mouse Events
Similar to all other input methods, you first have to enable mouse input via the follow-
ing:
self.isMouseEnabled = YES;
Then your layer will start receiving CCMouseEventDelegate protocol messages,
of which there are quite a few:
// received when the mouse moves with no button pressed
-(BOOL) ccMouseMoved:(NSEvent*)event {}
// received when the mouse moves while the corresponding button is held down
-(BOOL) ccMouseDragged:(NSEvent*)event {}
-(BOOL) ccRightMouseDragged:(NSEvent*)event {}
-(BOOL) ccOtherMouseDragged:(NSEvent*)event {}
Search Nedrilad ::




Custom Search