Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including gm-tick with all npm packages installed. Try it out:

var gmTick = require("gm-tick")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

gm-tick v1.0.2

Single, managed animation frame loop for games, animations and audio functions.


A single animationFrame/timeout loop with normalised output across browsers. Callbacks are passed as parameters the time elapsed since the callback was added and a function to stop the callback from being called again.

Uses requestAnimationFrame and microsecond timings if the browser supports it.

Supports global pause and resume, and pause and resume on the level of individual tasks.

This module has been used extensively in co-ordination animations, supporting game loops and web audio stuff. It is solid.



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


    $ component install charlottegore/tick
  var tick = require('tick');



Adds a callback to the loop to be called every tick. When the callback fires is is passed the time in milliseconds (and, if available, microseconds) since the callback was added. Returns a handle object.


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

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


> 1.12244043334424
> 4.32443350003422
> 4994.00000000598
> 5011.00000000422
> stopped



Pause everything. No callbacks will fire as long as it remains paused.



Resume everything. Elapsed time data passed to callbacks are adjusted to account for time spent paused.


Returns a normalised (relative to the timings passed to callbacks) 'time' according to Tick, which may vary depending on whether it's using performance or Date for timings. time() returns the time elapsed since the page loaded.

Handle API

When a callback is added to Tick, a handle object is returned. This is their API.


Stop the callback from ever being fired again.

> var handle = require('tick').add(callback);
> // callback is being called on every tick
> handle.stop();
> // callback has been removed


Prevent this callback from being called until resumed.

> var handle = require('tick').add(callback);
> // callback is being called on every tick
> handle.pause();
> // callback has been paused


Let a callback be called after being paused.

> handle.pause();
> // callback won't fire until resumed
> handle.resume();
> // callback fires again.




RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free