a Timer object to manage timing related function (FPS, Game Tick, Time...)
There is no constructor function for me.timer
Members
-
static fps :Number
-
Last measured fps rate.
This feature is disabled by default, unless the debugPanel is enabled/visible -
static interpolation :Boolean
-
Enable/disable frame interpolation
- Default Value:
- false
- See:
-
static lastUpdate :Date
-
Last update time.
Use this value to implement frame prediction in drawing events, for creating smooth motion while running game update logic at a lower fps. -
static maxfps :Number
-
Set the maximum target display frame per second
- Default Value:
- 60
- See:
-
static tick :Number
-
Last game tick value.
Use this value to scale velocities during frame drops due to slow hardware or when setting an FPS limit. (Seeme.timer.maxfps
) This feature is disabled by default. Enable me.timer.interpolation to use it.
Methods
-
static clearInterval(intervalID)
-
Clears the Interval set by me.timer.setInterval().
Parameters:
Name Type Description intervalID
Number ID of the interval to be cleared
-
static clearTimeout(timeoutID)
-
Clears the delay set by me.timer.setTimeout().
Parameters:
Name Type Description timeoutID
Number ID of the timeout to be cleared
-
static getDelta() → {Number}
-
Return elapsed time in milliseconds since the last update
Returns:
Number -
static getTime() → {Number}
-
Return the current timestamp in milliseconds
since the game has started or since linux epoch (based on browser support for High Resolution Timer)Returns:
Number -
static setInterval(fn, delay, pauseableopt, …paramopt) → {Number}
-
Calls a function continously at the specified interval. See setTimeout to call function a single time.
Parameters:
Name Type Attributes Default Description fn
function the function to execute
delay
Number the number of milliseconds (thousandths of a second) on how often to execute the function
pauseable
Boolean <optional>
true respects the pause state of the engine.
param
* <optional>
<repeatable>
optional parameters which are passed through to the function specified by fn once the timer expires.
Returns:
Number -The numerical ID of the timer, which can be used later with me.timer.clearInterval().
Example
// set a timer to call "myFunction" every 1000ms me.timer.setInterval(myFunction, 1000); // set a timer to call "myFunction" every 1000ms (respecting the pause state) and passing param1 and param2 me.timer.setInterval(myFunction, 1000, true, param1, param2);
-
static setTimeout(fn, delay, pauseableopt, …paramopt) → {Number}
-
Calls a function once after a specified delay. See me.timer.setInterval to repeativly call a function.
Parameters:
Name Type Attributes Default Description fn
function the function you want to execute after delay milliseconds.
delay
Number the number of milliseconds (thousandths of a second) that the function call should be delayed by.
pauseable
Boolean <optional>
true respects the pause state of the engine.
param
* <optional>
<repeatable>
optional parameters which are passed through to the function specified by fn once the timer expires.
Returns:
Number -The numerical ID of the timer, which can be used later with me.timer.clearTimeout().
Example
// set a timer to call "myFunction" after 1000ms me.timer.setTimeout(myFunction, 1000); // set a timer to call "myFunction" after 1000ms (respecting the pause state) and passing param1 and param2 me.timer.setTimeout(myFunction, 1000, true, param1, param2);