DruggedBunny's DeltaTiming to a module.?

Monkey Forums/Monkey Programming/DruggedBunny's DeltaTiming to a module.?

Amon(Posted 2012) [#1]
Don't know how to do it. Can someone turn it in to a module so that I can simply use 'import deltatiming'.

Is this possible?


GC-Martijn(Posted 2012) [#2]
I use this

deletatimer.monkey

Strict
Import mojo.app

Class DeltaTimer
	Field fps:Float = 60
	Field currentticks:Float
	Field lastticks:Float
	Field frametime:Float
	Field delta:Float
	
	Method New(inpfps:Float)
		fps = inpfps
		lastticks = Millisecs()
	End
	
	Method UpdateDelta:Void()
		currentticks = Millisecs()
		frametime = currentticks - lastticks
		delta = frametime / (1000.0 / fps )
		lastticks = currentticks
	End
End




then make it a global so all classes /methods can reach it
Import deltatimer ' import the file
Global dt:DeltaTimer ' next line make it global


in the game class do this
Method OnCreate:Int()
 		dt = New DeltaTimer(30) ' or something else
		SetUpdateRate dt.fps
		
		' do things
		Return 0
	End
	
	Method OnUpdate:Int()
		dt.UpdateDelta()

		' do things
		Return 0
	End



then you can use it in all classes like this
y=y+10 * dt.delta



Amon(Posted 2012) [#3]
Hey man thanks for that! Working perfectly. :D


GC-Martijn(Posted 2012) [#4]
I found most of it in the examples (bananas)