Class Timer

a Timer class to manage timing related function (FPS, Game Tick, Time...)

See

timer the default global timer instance

Constructors

constructor

Properties

delta

delta: number

fps

fps: number

framecount

framecount: number

framedelta

framedelta: number

interpolation

interpolation: boolean

last

last: number

maxfps

maxfps: number

minstep

minstep: number

now

now: number

step

step: number

tick

tick: number

timerId

timerId: number

timers

timers: {
args: any[];
delay: number;
elapsed: number;
fn: ((...args: any[]) => any);
pauseable: boolean;
repeat: boolean;
timerId: number;
}[]

Methods

clearInterval

  • clearInterval(intervalID): void
  • cancels the timed, repeating action which was previously established by a call to setInterval().

    Parameters

    • intervalID: number

      ID of the interval to be cleared

    Returns void

clearTimeout

  • clearTimeout(timeoutID): void
  • Cancels a timeout previously established by calling setTimeout().

    Parameters

    • timeoutID: number

      ID of the timeout to be cancelled

    Returns void

getDelta

getTime

  • 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

    current time

setInterval

  • setInterval(fn, delay, pauseable?, ...args): number
  • Calls a function continously at the specified interval. See setTimeout to call function a single time.

    Parameters

    • fn: ((...args: any[]) => any)

      the function to execute

        • (...args): any
        • Parameters

          • Rest...args: any[]

          Returns any

    • delay: number

      the number of milliseconds (thousandths of a second) on how often to execute the function

    • Optionalpauseable: boolean

      respects the pause state of the engine.

    • Rest...args: any[]

      optional parameters which are passed through to the function specified by fn once the timer expires.

    Returns 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().

    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);

setTimeout

  • setTimeout(fn, delay, pauseable?, ...args): number
  • Calls a function once after a specified delay. See me.timer.setInterval to repeativly call a function.

    Parameters

    • fn: ((...args: any[]) => any)

      the function you want to execute after delay milliseconds.

        • (...args): any
        • Parameters

          • Rest...args: any[]

          Returns any

    • delay: number

      the number of milliseconds (thousandths of a second) that the function call should be delayed by.

    • Optionalpauseable: boolean

      respects the pause state of the engine.

    • Rest...args: any[]

      optional parameters which are passed through to the function specified by fn once the timer expires.

    Returns number

    a positive integer value which identifies the timer created by the call to setTimeout(), 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);

Settings

Member Visibility

On This Page

AltStyle によって変換されたページ (->オリジナル) /