@web-engine-dev/time / TimeManager
Interface: TimeManager
The TimeManager handles all time-related functionality
Example
const tm = createTimeManager();
function loop(timestamp: number): void {
tm.update(timestamp);
while (tm.shouldFixedUpdate()) {
physics(tm.fixedTime.timestep);
tm.consumeFixedStep();
}
render(tm.fixedTime.alpha);
requestAnimationFrame(loop);
}Properties
fixedTime
readonlyfixedTime:FixedTime
Get the fixed time state
time
readonlytime:Time
Get the current time state
Methods
consumeFixedStep()
consumeFixedStep():
void
Consume one fixed timestep from the accumulator
Returns
void
createStopwatch()
createStopwatch():
Stopwatch
Create a new stopwatch
Returns
createTimer()
createTimer(
config):Timer
Create a new timer
Parameters
config
Timer configuration
Returns
Timer instance
getTimer()
getTimer(
id):Timer|undefined
Get a timer by ID
Parameters
id
string
Timer identifier
Returns
Timer | undefined
isPaused()
isPaused():
boolean
Check if time is paused
Returns
boolean
pause()
pause():
void
Pause time (sets timeScale to 0)
Returns
void
pauseTimer()
pauseTimer(
id):boolean
Pause a specific timer
Parameters
id
string
Timer identifier
Returns
boolean
true if the timer was found and paused
removeTimer()
removeTimer(
id):void
Remove a timer
Parameters
id
string
Timer identifier
Returns
void
resume()
resume():
void
Resume time (restores previous timeScale)
Returns
void
resumeTimer()
resumeTimer(
id):boolean
Resume a paused timer
Parameters
id
string
Timer identifier
Returns
boolean
true if the timer was found and resumed
setTimeScale()
setTimeScale(
scale):void
Set the time scale
Parameters
scale
number
Time scale multiplier
Returns
void
shouldFixedUpdate()
shouldFixedUpdate():
boolean
Check if a fixed update should run
Returns
boolean
true if there's accumulated time for a fixed update
update()
update(
timestamp):void
Update time for a new frame
Parameters
timestamp
number
Current timestamp in milliseconds (e.g., from requestAnimationFrame)
Returns
void
updateTimers()
updateTimers(
delta):void
Update all active timers
Parameters
delta
number
Delta time in seconds
Returns
void