Manages the properties associated with time.

// using deltaTime to increment a timer
this.timer += this.timeManager.deltaTime;

// using physicsDeltaTime within a physics component to move the object it belongs to
this.transform.position.x += speed * this.timeManager.physicsDeltaTime;

// stop all time-related interactions by setting the scale to zero
this.timeManager.timeScale = 0;

// set an interval that will be cleared after being called 5 times
const intervalId = timeManager.setInterval({
callback: () => console.log("Will be called 5 times!"),
delay: 1000,
times: 5,
});

// set an interval that will be called indefinitely
const intervalId = timeManager.setInterval({
callback: () => console.log("Will be called indefinitely!"),
delay: 1000,
});

// set an interval that will be called immediately and indefinitely
const intervalId = timeManager.setInterval({
callback: () => console.log("Will be called immediately and indefinitely!"),
delay: 1000,
executeImmediately: true,
});

// clear the interval with the given id
this.timeManager.clearInterval(intervalId);

Constructors

Properties

browserDeltaTime: number = 0

The time difference, in seconds, between the last frame of and the current frame recorded by the browser.

timeScale: number = 1

The scale on which time passes. The default value is 1.
For example, if set to 2, the time will run at twice the speed.
If set to 0.5, it will run at half the speed.
If set to 0, everything associated with the time will stop.

unscaledDeltaTime: number = 0

The time difference, in seconds, between the last frame and the current frame, unaffected by the scale.

unscaledPhysicsDeltaTime: number = 0

The time difference, in seconds, between the last physics frame and the current one, unaffected by the scale.

Accessors

  • get deltaTime(): number
  • The time difference, in seconds, between the last frame and the current frame.

    Returns number

  • get physicsDeltaTime(): number
  • The time difference, in seconds, between the last physics frame and the current one.

    Returns number

Methods

  • Clears the interval with the given id.

    Parameters

    • intervalId: number

    Returns void

  • Sets a timer which executes a function repeatedly at a fixed time interval.
    If times is provided, the interval will be cleared after the function has been called that many times.
    But if times is not provided, the interval will continue until it is cleared.
    If executeImmediately is set to true, the function will be called immediately after the interval is set.
    Intervals are cleared when loading a new scene.

    Parameters

    Returns number

    intervalId

    const intervalId = timeManager.setInterval({
    callback: () => console.log("Will be called 5 times!"),
    delay: 1000,
    times: 5,
    });
    const intervalId = timeManager.setInterval({
    callback: () => console.log("Will be called indefinitely!"),
    delay: 1000,
    });
    const intervalId = timeManager.setInterval({
    callback: () => console.log("Will be called immediately and indefinitely!"),
    delay: 1000,
    executeImmediately: true,
    });