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 Rob2001
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

Comments

Dax Trajero2006
is it me or is this not smooth at all ?


Gabriel2010
is it me or is this not smooth at all?

It's not you. This won't be remotely smooth without tweening. Blitz3D implements tweening for you (in 3D). If you want to use this and have a smooth refresh, you need to code your own tweening.


Code Archives Forum