How Can I get keyboard input in a SpriteKit Game?

后端 未结 4 1378
刺人心
刺人心 2020-12-11 16:59

I\'m a beginner in SpriteKit programming, and have been trying to figure out how to handle input from the keyboard.

What I\'ve found so far is that you should subcla

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-11 17:42

    If you want to know whenever a key is pressed, you should subscribe to the global event manager.

    [NSEvent addGlobalMonitorForEventsMatchingMask:(NSKeyDownMask) handler:^(NSEvent *event) {
    [NSEvent removeMonitor:event];
    

    This will call the handler when ever a key is pressed.

提交回复
热议问题