Code archives/Graphics/Blitz3D speed timing done in 2D (castle demo stuff in 2D)

This code has been declared by its author to be Public Domain code.

Download source code

Blitz3D speed timing done in 2D (castle demo stuff in 2D) by Rob
(Posted 25 years ago)
Reason this exists is because its a cheap way of speeding up the game when the pc slows down, and slowing down the game when the pc speeds up.

In short - a constant framerate. It's simply ripped from the castle demo for Blitz3D to work under 2D conditions. My deltatime example below this thread is smoother, but takes more work.
;logic framerate, not screen framerate.
Const FPS=60
Global x#,period#,time#,tween#,elapsed#

Graphics 640,480,16,2
SetBuffer BackBuffer()

;setup fps
period=1000/FPS
time=MilliSecs()-period

While Not KeyHit(1)

	Repeat
		elapsed=MilliSecs()-time
	Until elapsed
	tween=Float(elapsed)/Float(period)
	While tween>=1
		time=time+period
		tween=tween-1

		;update logic
		UpdateGame()
		
	Wend	

	;draw display
	DrawGame()

Wend
End

Function UpdateGame()
	x=x+1
	If x>640 Then x=0
End Function

Function DrawGame()
	Cls


	Oval x,32,16,16
	Oval x,64,16,16
	;etc


	Flip 0
End Function