If you see my other question, you'll know that I'm starting to try making simple 2d games on mac. There I was deciding which library to use (OpenGL or Quartz), but no matter what I'll have to use Cocoa to make it a nice Mac application, and for the window and the view (with OpenGL, NSOpenGLView). Obviously for a game, the view will have to redraw many times per second. To make a view redraw, you need to do [view setNeedsDisplay:YES];
, but I read that you shouldn't do this many times (because it costs a lot). But how am I supposed to redraw the view e.g. at a reasonable fps for a 2d game? Thanks.
views:
147answers:
1
+2
A:
The "only redraw if you have to" rule doesn't really apply to games. Games usually try to redraw at the refresh rate of the monitor, or as close to that rate as possible.
This page describes how to make on OpenGL rendering loop in cocoa: http://developer.apple.com/mac/library/qa/qa2004/qa1385.html
Tom Dalling
2009-11-18 23:54:04
Thanks I'll check that out.
Mk12
2009-11-18 23:58:21
Apple have said that you shouldn't write your loop as "draw as fast as possible". You should limit your drawing to something reasonable like 60Hz; otherwise, you will waste CPU time doing nothing useful. If you're vsync'd, this should happen automatically for you. If not, please put a rate limiter in there. Your laptop users' laps will thank you.
Daniel Yankowsky
2009-11-19 00:18:54
I just assumed the reader would know that vsync limits the "possible" in "as fast as possible". I should have been more clear.
Tom Dalling
2009-11-19 01:35:53
Thanks, accepted, that link was very helpful.
Mk12
2009-11-19 03:18:32