O'Reilly logo

Monkey Game Development by Michael Hartlef

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — implementing the GetDeltaTime method

This method will calculate the time it took from its last call in milliseconds:

  1. Insert a new method called GetDeltaTime. It will return an Int value.
    Method GetDeltaTime:Int()
    
  2. Compute deltaTime as the result of a call to Millisecs minus lastTime.
    deltaTime = Millisecs() - lastTime
    
  3. Then, add the current deltaTime value to lastTime.
    lastTime += deltaTime
    
  4. Return deltaTime and close the method.
    Return deltaTime
    End
    

What just happened?

To calculate how long it took between two update processes, we created a method that will do just that. Determine the current time in milliseconds, and calculate how long it took from the last time this method was called. The result will be used to determine a speed factor ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required