Fix Your Timestep!

BlitzMax Forums/BlitzMax Programming/Fix Your Timestep!

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

So with the interest in my game on the forum, I thought I'd revive this thread to see if anyone can help me with my last stumbling block.

As I mentioned before I'm happily using the frameskip + tweening code at frame rates higher than the 60hz my logic runs at. However, when I introduce a delay of 17ms to ensure that it runs at under 60hz (and the nearest would be 30hz) it seems to jerk nastily. This is my code:


	Const FPS:Int = 60
	Const FRAMELENGTH:Int = 1000 / FPS
	Const MAX_FRAMESKIP:Int = 5
	
	Local nextframetime:Double = MilliSecs()
	Local loops:Int
	Local tween:Float

	Repeat

		' THE BIG BIT
		
		loops = 0	
		
		Local ms:Double=MilliSecs()
		
		While (ms>nextframetime And loops < MAX_FRAMESKIP)
			all.update()
			nextframetime:+ FRAMELENGTH
			loops:+ 1
		Wend
		
		tween=Float(ms+FRAMELENGTH-nextframetime)/Float(FRAMELENGTH)

		Cls
		
		all.draw(tween)

	Until 0