iDevGames Forums
smooth animation - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: smooth animation (/thread-7356.html)



smooth animation - honkFactory - Feb 2, 2003 04:26 PM

Howdy,
I am developing a game with animation. I have an NSTimer that is set to fire every few milliseconds, but the actual fps is between 45 and 70 on my computer depending on how detailed I render the objects. Up until now, every time the screen is updated I the animated scene is updated by the same amount, regardless of how time has elapsed since the last time the scene was drawn. This means that objects move across the screen more slowly when the scene is drawn with more detail and on a different computer the objects would move across the screen at a rate proportional to the speed of that computer. Clearly thats not cool.
So, what I need to do is make the amount by which an object is moved on the screen dependent on how much time has elapsed since the last drawing. I can thing of two ways by which I might do this.
1) Give every object a velocity and use that velocity to calculate the distance the object has traveled across the screen since the last drawing.
2) Figure out what the refresh rate of the display is and then check to see if one or more refresh cycles have passed since the last drawing. If so, step the animation forward the proper number of cycles and redraw the screen.
In the past I have tried (briefly) to get the fist approach to work, but the animation appeared jerky. I was using NSDate methods to get the elapse time between drawing. I believe the problem was I was not taking the refresh rate into account. If anyone has any advice I would be grateful.
A.W.


smooth animation - w_reade - Feb 2, 2003 04:32 PM

AFAIK, (1) is the usual method. I wasn't aware that there were problems with NSDate's accuracy, so I'm not sure what your problems are there. Anyone?

I'd steer clear of (2); it smacks of unnecessary complication, and there's always the possibility that drawing'll take more than one refresh cycle, which will just confuse matters further.


smooth animation - honkFactory - Feb 2, 2003 04:49 PM

I quickly reimplimented approach 1 and in works great. I am not sure what I did last time to screw it up since this approach is quite simple but screw it up I did. Thanks. I was about to go down path #2 for no good reason.
A.W.