smooth animation

honkFactory
Unregistered
 
Post: #1
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.
Quote this message in a reply
w_reade
Unregistered
 
Post: #2
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.
Quote this message in a reply
honkFactory
Unregistered
 
Post: #3
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Smooth acceleration in every direction. Honey Sharma 1 4,336 Aug 16, 2011 01:37 AM
Last Post: PoseMotion
  Smooth movement with the accelerometer? - Like a labyrinth game. DotSlashSlash 12 10,545 Jul 14, 2010 07:15 AM
Last Post: ThemsAllTook
  Requesting Help: Smooth keyframe interpolation algorithm whogben 4 4,673 Jan 5, 2009 11:15 PM
Last Post: whogben