Skip to content

hughsk/delta-timer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

delta-timer

A simple module for measuring time in animations. If you're writing a game though, read this first and consider looking at ticker instead.

Installation

npm install delta-timer

Usage

timer = require('delta-time')([now])

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.

timer()

Returns the amount of time since timer was last called.

timer.reset()

Resets the timer - the next return value will be 0.

timer.pause()

Disables the timer. timer() will always return 0 during this time.

timer.resume()

Resumes the timer - if previously paused, this will reset it too to avoid skipping forward too far in time.

timer.now()

Returns the current timestamp.

Example

var timer = require('delta-timer')()
  , raf = require('raf')

var scene = require('./scene')

raf(window).on('data', function() {
  var dt = timer()
  scene.tick(dt)
})

About

A simple module for measuring time in animations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published