Game Timing

BlitzMax Forums/BlitzMax Programming/Game 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.

This might help:


' /  /  /  /  /  /  /  /  /  /  /  /  /  /  /  /

'		 D E L T A  T I M E

'------------------------------------------------------------------------
	Type Delta 
	'		
	'-----------------------------------------------------
	' This type is Fully global. Which means you'll always 
	' refere to it as Delta.Start() , Delta.Time(),
	' Delta.Update() 
	'
	' You shouldn't create instances of this type!
	' DeltaTime is same for all your objects!
	'
	Global DeltaTime!
	Global TimeDelay%
	
	'Run this once before your main loop
	'If you don't there will be a jump in deltatime
	Function Start()
		TimeDelay = MilliSecs()
	End Function
	
	'Everytime where you want to get the deltatime
	'call this: Delta.Time
	'You should multiply this to every place which 
	'adds to you position/speed/acceleration
	'
	' The basic rule is to add deltatime to all
	' things which gets added to every frame
	' Like Speed:+ 10*Delta.Time
	'
	' If you use the Vector Library simply use 
	' AddDelta() instead of Add()
	' And
	' AddDeltaNew() Instead of AddNew()
	
	Function Time!()
	
		Return DeltaTime!
	
	End Function
	
	'Put this once in your main loop
	'it calculates the current deltatime
	'depeding on your framerate or more exact
	'the time between each/the last frame.
	Function Update()
	'_____________________________________________________ 
	'Purpose: Calculates DeltaTime , put it in mainloop			
	'-----------------------------------------------------	
			DeltaTime = ( MilliSecs()- TimeDelay )*0.001
			TimeDelay  = MilliSecs()			
		
	EndFunction
		
End Type	' /  /  /  /  /  /  /  /  /  /  /  /  /  /  /  /
'----------------------------------------------------------------------------------------	


I hope the comments are still valid. I like having a Delta Type, it really makes it cleaner.