npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

animation-loops

v2.0.4

Published

Managed animationFrame looping for games, animations and web audio functions.

Downloads

191

Readme

Animation Loops / Tick

browser support

Build Status

Low level games and graphics utility. Any situation where you need something to run around 60 times a second, animation-loops is your friend.

  • Add callbacks to be executed every requestAnimationFrame
  • All callbacks get the highest precision time elapsed and delta information available
  • Pause, resume and stop individual animations.
  • Globally Pause, resume and stop all animations.
  • Applications: Game loops, animation loops etc.
  • Covered by tests
  • Uses a polyfilled/shimed requestAnimationFrame

Installation

Browserify/NPM

Current tested version:

    $ npm install --save animation-loops
  var tick = require('animation-loops');

API

.add( function(elased, delta, stop) { ... } [, start])

Adds a callback to be executed every animationFrame which, when executed, is passed the amount of time elapsed and the time since the last frame.

Example

var handle = tick.add( function( elapsed, delta, stop ){

	console.log( elapsed, delta );

	if( elapsed > 5000){
       stop(); // make sure the callback won't fire again 
       console.log('stopped');   		
	}

});

Optionally a 'start' parameter can be passed to .add(). Callbacks begin firing on animationFrames immediately, but the elapsed parameter will be negative, counting up to zero until the start time arrives, at which point it continues as normal. Very NASA.

.pause()

Globally pauses all running animations. When they resume, the elapsed and delta parameters in your callbacks are automatically adjusted to remove the time spent paused.

tick.pause();

.resume()

Globally resume all paused animations.

tick.resume();

.time()

Returns the current time using the highest precision timer available in the environment. This is to ensure that developers can code against one single source of time that will be consistent with animation-loops and not have to worry about differences between Date and performance.

.FPS()

Yay metrics! Returns the current FPS. It is not averaged.

var lastFPS = tick.FPS();

Handle API

When a callback is added to animation-loops, a handle object is returned, which gives control to individual animations/loops.

var handle = tick.add(function (){
    //
})

handle.stop()

Immediately stop an animation/loop. It cannot be restarted.

// run our callback for about 100ms then stop.
var handle = tick.add(callback);
setTimeout(function(){
  // this stops just this animation but leaves the others running.
  handle.stop();
}, 100)

.pause()

Pause the animation/loop.

// run the animation for 100ms then pause
var handle = tick.add(callback);
setTimeout(function (){
  handle.pause();
}, 100)

.resume()

Resume the animation/loop

// run the animation for 100ms, pause for 100ms, then resume it again..
var handle = tick.add(callback);
setTimeout(function (){
  handle.pause();
}, 100)
setTimeout(function (){
  handle.resume();
}, 200)

Tests

Assuming you have grunt-cli already installed, and you've cloned the repo:

# Just the once...
$ npm install
grunt test

History

This module used to be known as tick. That module is still avaliable on npm as gm-tick but this version, which adds FPS metrics, optimisations and test coverage is to be prefered.

License

MIT