0
votes

I'm very new to objC and game programming in general, so excuse me if this is a question many of you could do [self facepalm];

I'm trying to setup a game loop (NSObject) as a controller. Also there is a NSOpenGLView connected with the Window via Interface Builder (MainMenu.xib). The loop should handle all keyboard input and manage what to draw on the view.

I figured out, that I can catch key events on the view with - (void)keyDown:(NSEvent *)theEvent. How could I pass this input to the controller/loop?

For sending the keyinput to the loop I used the NSNotificationCenter with postNotificationName. But it seems to be slow and 'laggy'. This can't be the right way to do it.

Any tips would be great!

1

1 Answers

0
votes

Use the same way NSControl uses to deliver events. Or do as it's done is iOS's UIControl's addTarget:action:forControlEvents:.

The idea is to register some objects as "listeners" (target) to such event, and the methods (actions) that should be called when the event is triggered. You can make things simple for you by declaring some protocol for your view and make each class that requires to receive the events conform to it.