A simple module for measuring time in animations. If you're writing a game though, read this first and consider looking at ticker instead.
npm install delta-timer
Create a new timer. Optionally, you can pass in a custom method for
generating that returns a timestamp - otherwise, this will default to
the best available of performance.now
, Date.now
, or +new Date
.
Returns the amount of time since timer
was last called.
Resets the timer - the next return value will be 0.
Disables the timer. timer()
will always return 0 during this time.
Resumes the timer - if previously paused, this will reset it too to avoid skipping forward too far in time.
Returns the current timestamp.
var timer = require('delta-timer')()
, raf = require('raf')
var scene = require('./scene')
raf(window).on('data', function() {
var dt = timer()
scene.tick(dt)
})