1.1.0 • Published 6 years ago
@bastienrobert/clock v1.1.0
Install
npm install @bastienrobert/clockUsage
import Clock from '@bastienrobert/clock'
const clock = new Clock()
requestAnimationFrame(() => {
const delta = clock.update()
console.log(delta, clock.currentTime)
})API
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
Methods
| 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 |