1.1.0 • Published 4 years ago

@bastienrobert/clock v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Install

npm install @bastienrobert/clock

Usage

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 start
  • clock.state: current state of the clock (enum State is exported too for Typescript)
  • clock.now: latest Date.now() recorded by the clock
  • clock.last: latest Date.now() recorded before clock.now

Methods

MethodDescription
StartSet the current time to 0 and start the clock, returns state
ResumeResume 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
StopStop the current time (without reset of the current time), returns state
UpdateUpdate the current time, need to be in your loop, returns elapsed (delta) time between last call
1.1.0

4 years ago

1.0.0

5 years ago