Timer
class Timer
a Timer class to manage timing related function (FPS, Game Tick, Time...)
Summary
Properties from Timer
number |
|
boolean |
|
number |
|
number |
|
Public Properties
fps: number = 0
number
Last measured fps rate.
This feature is disabled by default, unless the debugPanel is enabled/visible.
interpolation: boolean = false
boolean
Enable/disable frame interpolation
maxfps: number = 60
number
Set the maximum target display frame per second
tick: number = 1
number
Last game tick value.
Use this value to scale velocities during frame drops due to slow hardware or when setting an FPS limit.
This feature is disabled by default (Enable interpolation to use it).
Public Methods
clearInterval(intervalID: number) → {}
cancels the timed, repeating action which was previously established by a call to setInterval().
Name | Type | Description |
---|---|---|
intervalID | number |
ID of the interval to be cleared |
clearTimeout(timeoutID: number) → {}
Cancels a timeout previously established by calling setTimeout().
Name | Type | Description |
---|---|---|
timeoutID | number |
ID of the timeout to be cancelled |
getDelta() → {number}
Return elapsed time in milliseconds since the last update
Type | Description |
---|---|
number |
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)
Type | Description |
---|---|
number |
setInterval(fn: Function, delay: number, pauseable: boolean, args: unknown) → {number}
Calls a function continously at the specified interval. See setTimeout to call function a single time.
// 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);
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. |
args | unknown |
optional parameters which are passed through to the function specified by fn once the timer expires. |
Type | Description |
---|---|
number |
a numeric, non-zero value which identifies the timer created by the call to setInterval(), which can be used later with me.timer.clearInterval(). |
setTimeout(fn: Function, delay: number, pauseable: boolean, args: unknown) → {number}
Calls a function once after a specified delay. See me.timer.setInterval to repeativly call a function.
// 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);
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. |
args | unknown |
optional parameters which are passed through to the function specified by fn once the timer expires. |
Type | Description |
---|---|
number |
a positive integer value which identifies the timer created by the call to setTimeout(), which can be used later with me.timer.clearTimeout(). |