animation

animation timing & handling

animation

Handles Animation Timing and Handling for you.

Uses requesAnimationFrame when running on browser side.

$ npm install animation
animation = new Animation({frame:'100ms'});
animation.on('tick', function (dt) { … });
animation.start();

surrender-cube uses this module to draw a rotating wireframe cube in terminal.

animation = new Animation({
    // defaults 
    execution: '5ms', // allowed execution time per animation tick 
    timeout:   null,  // maximum time of a animation tick interval 
    toggle:    false, // if true animation pauses and resumes itself when render queue gets empty or filled 
    frame:     '16ms' // time per frame 
});

Creates a new Animation controller.

animation.start();

Starts animation.

animation.stop();

Stops animation.

animation.pause();

When autotoggle is enabled the Animation pauses itself if the render queue is empty.

animation.resume();

When autotoggle is enabled the Animation resumes itself when the render queue gets filled again after it was emtpy.

animation.nextTick(function (dt) { … });

Given callback gets called on next animation tick when running and not paused.

animation.on('start', function () { … });

Emits start event every time the animation gets started.

animation.on('stop', function () { … });

Emits stop event every time the animation gets stopped.

animation.on('pause', function () { … });

Emits pause event every time the animation gets paused.

animation.on('resume', function () { … });

Emits resume event every time the animation gets resumed.

animation.on('tick', function (dt) { … });

Emits tick event every time the animation executes a animation tick.

dt is the time since last animation tick.

Use this to do your animation stuff.