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
|