Cocoa main loop updating

Cocoa main loop updating

If your function is working properly, it just works.

As always, it takes some effort to get Cocoa going.

Every once in a year or so I get an uncontrollable urge to write a game.

I like classic arcade games, the kind where you have a spaceship and zap alien monsters.

When the window is minimized or goes out of focus, the game is put into a paused state and the timer is stopped.

We ask for one more redraw so that we can show a nice pause screen.

In code, toggling screen mode is always a bit of a hassle.If you google around for “NSOpen GLView tutorial” or “mac opengl” you’ll find a lot of old code and horror stories. With SDL you just set up a main loop, redraw the screen, do game mechanics, and call to sleep some milliseconds for getting the frame rate right.Using Open GL on the Mac used to be much harder than it is today. Like always in Cocoa, create your own new view class derived from an already existing view class: @implementation Game View - (void)prepare Open GL - (void)draw Rect:(NSRect)dirty Rect - (void)reshape - (BOOL)accepts First Responder - (void)key Down:(NSEvent *)the Event - (void)key Up:(NSEvent *)the Event @end to update Open GL’s viewport. In Cocoa, you can not have a main loop because it would interfere with the invisible (it’s hidden! So to get a frame rate going you have to set up a timer that periodically updates the screen.Coming from the Linux world, I became somewhat attached to the SDL library.SDL is great but under OS X, it doesn’t feel native and the end product isn’t as good.

cocoa main loop updating-6cocoa main loop updating-23cocoa main loop updating-17

Join our conversation (12 Comments).
Click Here To Leave Your Comment Cocoa main loop updating.


Leave a Reply

Your email address will not be published. Required fields are marked *