phaser - v4.0.0-rc.4
    Preparing search index...

    Provides methods for managing an elapse timer on a Game Object. The timer is used to drive animations and other time-based effects.

    This is not necessary for normal animations. It is intended to drive shader effects that require a time value.

    If you are adding this component to a Game Object, ensure that you register a preUpdate method on the Game Object, e.g.:

    //  Overrides Game Object method
    addedToScene: function ()
    {
    this.scene.sys.updateList.add(this);
    },

    // Overrides Game Object method
    removedFromScene: function ()
    {
    this.scene.sys.updateList.remove(this);
    },

    preUpdate: function (time, delta)
    {
    this.updateTimer(time, delta);
    }
    interface ElapseTimer {
        timeElapsed: number;
        timeElapsedResetPeriod: number;
        timePaused: boolean;
        resetTimer(ms?: number): this;
        setTimerPaused(paused?: boolean): this;
        setTimerResetPeriod(period: number): this;
        updateTimer(time: number, delta: number): this;
    }

    Implemented by

    Index

    Properties

    timeElapsed: number

    The time elapsed since timer initialization, in milliseconds.

    timeElapsedResetPeriod: number

    The time after which timeElapsed will reset, in milliseconds. By default, this is 1 hour. If you use the timer for animations, you can set this to a period that matches the animation durations.

    This is necessary for the timer to avoid floating-point precision issues in shaders. A float32 can represent a few hours of milliseconds accurately, but the precision decreases as the value increases.

    timePaused: boolean

    Whether the elapse timer is paused.

    Methods

    • Reset the elapse timer for this game object.

      Parameters

      • Optionalms: number

        The time to reset the timer to. Default 0.

      Returns this

    • Pauses or resumes the elapse timer for this game object.

      Parameters

      • Optionalpaused: boolean

        Pause state (true to pause, false to unpause). If not specified, the timer will unpause.

      Returns this

    • Set the reset period for the elapse timer for this game object.

      Parameters

      • period: number

        The time after which timeElapsed will reset, in milliseconds.

      Returns this

    • Update the elapse timer for this game object. This should be called automatically by the preUpdate method.

      Override this method to create more advanced time management, or set it to a NOOP function to disable the timer update. If you want to control animations with a tween or input system, disabling the timer update could be useful.

      Parameters

      • time: number

        The current time in milliseconds.

      • delta: number

        The time since the last update, in milliseconds.

      Returns this