0.0.0 • Published 5 years ago

clock-manager v0.0.0

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

clock-manager

Latest NPM release MIT License

demos

Usage

$ npm install --save clock-manager

1. make an instance and start it

const clock = new ClockManager();
clock.start();

2. update in your requestAnimationFrames

You can get deltaTime and elapsedTime then.

( anim() {

	requestAnimationFrame( anim );
	clock.update();
	const delta = clock.deltaTime;
	const elapsed = clock.elapsedTime;
	updateSOmething( delta );
	renderSomething();

} )();

even in a separate place

function renderSomething() {

	const updatedDelta = clock.deltaTime;

}

other features

  • clock.start() : start / restart.
  • clock.stop() : stop the clock.
  • clock.elapsedTime( number ) : time travel like, rewind and forward.
  • clock.update() : update clock for the delta frame. this is usually executed in the beginning of requestAnimationFrame.

and getters:

  • clock.deltaTime
  • clock.elapsedTime