Timing

BlitzMax Forums/BlitzMax Beginners Area/Timing

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.

Sure sure, no problem :-)


Strict


Graphics 800,600,0


Global fps
Local tfps,xfps
Local time, tdif:Float
' all movement values are multiplied by tdif to scale them to the actual fps
' this is not using fps as fps is constant for a second and does not reflect
' the real fps every loop

Local move_x:Float	= GraphicsWidth () / 2
Local move_y:Float	= GraphicsHeight () / 2
Local dir_x:Float	= 60			' 60 pixels per second
Local dir_y:Float	= 60			' 60 pixels per second
time				= MilliSecs ()
While Not KeyHit (key_escape)
	
	Cls
		
	move_x	:+ dir_x * tdif
	move_y	:+ dir_y * tdif
	If move_x > GraphicsWidth () - 10 Or move_x < 10 dir_x = - dir_x
	If move_y > GraphicsHeight () - 10 Or move_y < 10 dir_y = - dir_y

		
	SetColor 0,0,200
	DrawOval move_x,move_y,10,10
		
	SetColor 255,255,255
	DrawText "FPS: " + fps,0,0
	Flip
	FlushMem
	tdif		= Float(MilliSecs () - time)/1000
	time		= MilliSecs ()
	If time - tfps > 999
		fps		= xfps
		xfps	= 0
		tfps	= time
	EndIf
	xfps		:+ 1
Wend