Regulating anim speed with delta timing?

Blitz3D Forums/Blitz3D Programming/Regulating anim speed with delta timing?

Axeman:

Set the speeds using the "Animate" command so the animations look right on the computer you're testing on.

Then, set "Test_FPS" to the typical FPS of your game on that same computer.

Then, use the following code, or something equivalent, to calibrate the animations.


Global Max_FPS = 60	; Maximum FPS on any computer
Global Test_FPS = 35    ; Typical FPS on test computer
Global FramePeriod = 1000 / Max_FPS

Global FrameDiff#
Global FrameFactor#
Global FPS#		; Actual FPS on any computer


Previous = FrameTime = MilliSecs() - FramePeriod

;Main Loop

Repeat
	Now = MilliSecs()
	FrameDiff = Now - Previous
	Previous = Now
	FPS = 1000.0/FrameDiff
	FrameFactor = Float(Test_FPS)/FPS

; Frame limiter
	While (FrameTime + FramePeriod) > MilliSecs()
		Delay 1
	Wend
	FrameTime = MilliSecs()

	UpdateGame()
	
	If FrameFactor > 3.0 FrameFactor = 3.0 ;a "reasonable limit"
	UpdateWorld(FrameFactor)
	RenderWorld
	Flip False
Forever