我正在尝试在我的原型中管理鼠标事件精灵套件 game.
我从问题中使用了以下方法SO_q https://stackoverflow.com/questions/17473176/how-to-detect-right-and-left-click-in-cocoa
- (void) mouseDown: (NSEvent*) theEvent
{
NSLog(@"Click!");
}
- (void) rightMouseDown:(NSEvent*) theEvent
{
NSLog(@"DERECHA PULSADA!");
}
但检测右键单击的方法对我不起作用。我想检测鼠标右键的点击和放下。
如何检测鼠标单击何时被放下?
UPDATE:
我尝试使用以下方法,从Cocoa事件处理文档 https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/HandlingMouseEvents/HandlingMouseEvents.html#//apple_ref/doc/uid/10000060i-CH6-SW1.
- (void)mouseDown:(NSEvent *)theEvent
{
switch ([theEvent type])
{
case NSLeftMouseDown:
NSLog(@"ISQUIERDO down!");
break;
case NSLeftMouseUp:
NSLog(@"IZQDO soltado!");
break;
case RightMouseDown:
NSLog(@"DERECHO PUSSSHHH!");
break;
case NSRightMouseUp:
NSLog(@"Botón Derecho Soltado!");
break;
default:
/* Ignore any other kind of event. */
break;
}
return;
}
Result:仅处理左键单击事件。
阅读完后Cocoa事件处理文档 https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/HandlingMouseEvents/HandlingMouseEvents.html#//apple_ref/doc/uid/10000060i-CH6-SW1我尝试覆盖以下方法:
-(void)rightMouseDown:(NSEvent *)theEvent
{
NSLog(@"DERECHO PUSSSHHH!");
}
- (void)rightMouseUp:(NSEvent *)theEvent
{
NSLog(@"Botón Derecho Soltado!");
}
也没起作用。
UPDATE:
正如我之前所说,这些方法位于 Sprite-Kit 类中。这里是定义这些方法的类定义。
#import <SpriteKit/SpriteKit.h>
@interface OpcionesMenu : SKScene
@end