![]() |
|
NSTimer / animation framerate question - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Game Programming Fundamentals (/forum-7.html) +--- Thread: NSTimer / animation framerate question (/thread-4735.html) |
NSTimer / animation framerate question - MonitorFlickers - Dec 2, 2005 10:12 AM I have a simple little program that has a custom NSView which draws a field of stars moving across the screen- basically just an array of various integers that keep track of a bunch of white dots that scroll by on a black background. An NSTimer fires the redraw to make it animate. My problem is that I have the framerate speed for the NSTimer, as well as the number of stars (white dots) defined by the precompiler with #define but no matter how I change them something internally seems to be capping my framerate. It's easy enough to slow things down, I can reduce the timer firing speed. But when I increase the framerate variable, I eventually reach a certain point where it stops making the stars go by faster. I thought maybe my processor had just maxed out somehow through inefficient code or something, but then I changed the predefined number of stars from 60 to 300, and it animated at the exact same speed. I can't seem to figure out why, regardless of the amount of drawing, or the Timer speed, it seems to cap off at a certain framerate. Does it have something to do with the built-in setNeedsDisplay refresh rate or something? I'm very much a noob at Obj C but if anyone could give me some feedback on this I'd appreciate it! thank you! NSTimer / animation framerate question - TomorrowPlusX - Dec 2, 2005 10:56 AM I could be wrong, but I *think* that normal NSView drawing is beam-synced, meaning it wil never draw faster than the refresh rate of your video card. There may or may not be a way to turn this feature off. But consider, you're getting a cap for free -- there's no way your monitor could display what you're drawing any faster, anyway. What you should do, and you may be doing anyway, is to give your timer an interval of zero and keep track of the actual time between frame drawing via NSDate. Then, use a time based animation to progress your stars by the time interval between frames. You'll get a constant speed of motion regardless of wether your framerate is 20, 60, or 120 ( if you're running on a good CRT ). NSTimer / animation framerate question - ThemsAllTook - Dec 2, 2005 11:30 AM In general, it's a good idea to assume that your timer will not fire at predictable intervals. This article may be of some use to you: http://www.sacredsoftware.net/tutorials/Animation/TimeBasedAnimation.xhtml NSTimer / animation framerate question - kelvin - Dec 2, 2005 04:07 PM enable/disbable vsync in NSOpenGLContext. If you're doing single threaded game/drawing, then you can turn off your vsync for faster framerates. You'll get ugly tearing though, so I don't recommend it. Better to just do multithreading or some kind of independent game/drawing loop. NSTimer / animation framerate question - blobbo - Dec 2, 2005 04:52 PM You really shouldn't be modifying the speed of your animation by reducing or increasing your frames per second. Look into time-based animation. I have sample Cocoa code here: http://gamewiki.evolpenguin.com/index.php?title=Game_Loop_using_Physics_Units That works well. The actual problem is probably vsync, although your implementation seems like it will give you problems later on when someone runs your program on a machine that can't achieve the same fps as yours can. NSTimer / animation framerate question - MonitorFlickers - Dec 4, 2005 01:10 PM Thanks for the help, I'll check out those links!
|