Developped to be used with really old browsers and with or without module bundler.
Fast & ~550B gzipped
npm install @bastienrobert/clock
import Clock from '@bastienrobert/clock'
const clock = new Clock()
requestAnimationFrame(() => {
const delta = clock.update()
console.log(delta, clock.currentTime)
})
clock.currentTime
: elapsed time since the clock has been startclock.state
: current state of the clock (enum State is exported too for Typescript)clock.now
: latestDate.now()
recorded by the clockclock.last
: latestDate.now()
recorded beforeclock.now
Method | Description |
---|---|
Start | Set the current time to 0 and start the clock, returns state |
Resume | Resume the current time after STOP (the current time is computed with a delta-time, the elapsed time between stop and resume is included), returns state |
Stop | Stop the current time (without reset of the current time), returns state |
Update | Update the current time, need to be in your loop, returns elapsed (delta) time between last call |