This method will calculate the time it took from its last call in milliseconds:
1. Insert a new method called
GetDeltaTime
. It will return anInt
value.Method GetDeltaTime:Int()
2. Compute
deltaTime
as the result of a call toMillisecs
minuslastTime
.deltaTime = Millisecs() - lastTime
3. Then, add the current
deltaTime
value tolastTime
.lastTime += deltaTime
4. Return
deltaTime
and close the method.Return deltaTime End
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 for the engine's update process.