Game Development Reference
In-Depth Information
// received when the corresponding mouse button is pressed (left, right, other)
-(BOOL) ccMouseDown:(NSEvent*)event {}
-(BOOL) ccRightMouseDown:(NSEvent*)event {}
-(BOOL) ccOtherMouseDown:(NSEvent*)event {}
// received when the corresponding mouse button is released (left, right, other)
-(BOOL) ccMouseUp:(NSEvent*)event {}
-(BOOL) ccRightMouseUp:(NSEvent*)event {}
-(BOOL) ccOtherMouseUp:(NSEvent*)event {}
// received when the scroll wheel is turned
-(BOOL) ccScrollWheel:(NSEvent*)event {}
Because you get specific events for each mouse button, you mainly use the NSEvent
object to get the current mouse cursor position. You have to convert that position to
cocos2d coordinates via the Director's convertEventToGL method:
CGPoint mousePos = [[CCDirector sharedDirector] convertEventToGL:event];
Kobold2D users have to do no such thing. You can check at any time whether a mouse
button is pressed:
[[KKInput sharedInput] isMouseButtonDown:KKMouseButtonLeft];
The mouse position is also readily available and already converted to cocos2d coordin-
ates, so you can simply write this in a scheduled method to use a sprite as the mouse
cursor:
sprite.position = [KKInput sharedInput].mouseLocation;
Apple has a great tutorial on handling mouse events if you want to learn more about It:
http://developer.apple.com/library/mac/#documentation/Co-
coa/Conceptual/EventOverview/HandlingMouseEvents/Hand-
lingMouseEvents.html .
CCSprite
Search Nedrilad ::




Custom Search