@ujjwalvivek/tinyts
    Preparing search index...

    Class Timer

    A simple stopwatch-style timer using engine time or wall-clock time.

    Useful for cooldowns, timed events, lap timing, spawn intervals, etc.

    // 5-second cooldown using engine time (respects fixed-step)
    const cooldown = new Timer();
    if (cooldown.done(5)) {
    fireBullet();
    cooldown.reset();
    }

    // Real-time profiling using wall clock
    const profile = new Timer(false);
    heavyComputation();
    console.log(`took ${profile.elapsed().toFixed(2)}ms`);
    Index

    Constructors

    • Parameters

      • useEngineTime: boolean = true

        Whether to use the engine's fixed-step time (default: true).

      Returns Timer

    Methods

    • Returns true if duration seconds have elapsed.

      Parameters

      • duration: number

      Returns boolean

    • Seconds elapsed since start (or since last resume).

      Returns number

    • Milliseconds elapsed (convenience for elapsed() * 1000).

      Returns number

    • Returns true if the timer is currently paused.

      Returns boolean

    • Pause the timer. elapsed() will freeze until resume().

      Returns void

    • Returns the fraction [0, 1] of duration completed. Clamped so it never exceeds 1.

      Parameters

      • duration: number

      Returns number

    • Returns the remaining seconds before duration is reached. Returns 0 if already done.

      Parameters

      • duration: number

      Returns number

    • Reset the timer back to zero.

      Returns void