game timing schemes

BlitzMax Forums/BlitzMax Programming/game timing schemes

I like frame-rate independent timing. Sushimastas example works great when the game is running nice and fast - but lets say some process boots up in the background and slows it down, the frame-rate decreases - and with it so does the game speed! The idea behind independent timing is someone can be kicking it at 60FPS, and when something in the background pushes it to 30 fps, the actual game still runs at the same speed. This is the method I prefer.


Global deltaT#, lasttime = MilliSecs()

While Not(KeyHit(key_escape))
	DeltaT = Float(MilliSecs() - lasttime)/1000.0; lasttime = MilliSecs()
	
	game.update()
	game.draw()
	
	Flip; Cls; FlushMem
Wend

' An example moving a player

player.xVelocity = player.xVelocity + player.xAcceleration * DeltaT
player.x = player.x + player.xVelocity * DeltaT