On Wed, Feb 3, 2010 at 11:59 AM, Patrick Mullen
<saluk64007@xxxxxxxxx> wrote:
One method for having a smooth variable framerate, without the issues of variable time calculations, is to have a fixed time step. Each frame, you may process more than one timestep, if you need to in order to keep up. The timestep has a fixed amount of time it is supposed to similate, say, .02, which would be 60 times per second. If the user is able to run at 60 fps, they get very smooth animation, as only one step is occuring on each frame. If the user can only run at 30 fps, they will get two steps each frame, so it will be jerkier, but still accurate. If they can only run at 10 fps, you would set a limit on it (maybe the max is two timesteps in a frame), so things would be slower for them but maybe still playable.
def dostuff(dt):
man.x += speed*dt
GAMESPEED = .02
while 1:
dt = clock.tick()
max=2
while dt>0 and max:
dt -= GAMESPEED
max -= 1
dostuff(GAMESPEED)
There might be other problems with this, I've never done it this way, only seen it referred to. I know in some engines, like doom3, the physics of everything, game logic etc, happens at a fixed 30hz rate; whereas animation of the scene is much smoother.
I am usually lazy and just do clock.tick(30) lol.