【发布时间】:2014-05-27 19:17:45
【问题描述】:
我是 SpriteKit 编程的初学者,一直在尝试弄清楚如何处理来自键盘的输入。
到目前为止我发现你应该继承 NSResponder 并像这样实现它:
@interface AppDelegate : NSResponder <NSApplicationDelegate>
-(void)keyUp:(NSEvent *)theEvent;
-(void)keyDown:(NSEvent *)theEvent;
@end
@implementation AppDelegate
-(void)keyUp:(NSEvent *)theEvent
{
NSLog(@"Key Released");
}
-(void)keyDown:(NSEvent *)theEvent
{
NSLog(@"Key Pressed");
}
@end
显然,AppDelegate 的接口和实现中还有一些方法/属性,但我没有将它们放在那里以保持问题的相关性。
接下来,我将开始使用键码来检测正在按下哪些键,但 keyUp 和 keyDown 方法甚至不会被调用。我不知道为什么。
有什么帮助吗?
更新:
感谢您的回答!我发现你必须直接在你的场景类中实现keyUp 和keyDown,因为它们不会被 AppDelegate 调用。再次感谢您的帮助!
【问题讨论】:
标签: objective-c macos sprite-kit