pixi-animationloop
AnimationLoop is a plugin for Pixi.js v3.0.8 or higher to manage the animation frame, doing the basic time operations, like calculate delta, total time, start/stop loop, and more.
Installation
npm install pixi-animationloop
Usage
Browserify - Webpack
If you use Browserify or Webpack you can use pixi-animationloop like this:
var PIXI = ;var AnimationLoop = ; //AnimationLoop is added automatically to the PIXI namespace //create PIXI renderervar renderer = 800600;documentbody; var animationLoop = renderer;animationLoopstart;
Prebuilt files
var renderer = 800600;documentbody; var animationLoop = renderer;animationLoopstart;
Events
AnimationLoop extends from PIXI.utils.EventEmitter, and emit four events: start, stop, prerender, postrender and visibilitychange. More info: Node.js Events
animationLoop; animationLoop; //Before the renderer.render(stage) functionanimationLoop; //After the renderer.render(stage) functionanimationLoop; //when the visibility change, for example, when the user move on to other browser tab.animationLoop;
API
constructor( renderer [, stage])
The constructor
.renderer
Pixi.js renderer
.stage
Pixi.js container used as stage
.time
Total game time in seconds (stop the animation loop stops the time)
.realTime
Real time in seconds, since the first start
.delta
Delta time in seconds
.deltaMS
Delta time in milliseconds
.speed
Set the time speed (like 0.5, 1.5, 2, ...)
.maxFrame
Delta time can't be higher than maxFrame (in seconds)
.raf
Request animation frame ID
.isRunning
Used internally to know the state of the loop
.stopOnVisibilityChange
Stop the animation loop when the user move on to the other tab, when the user comes back the game will be resumed. (false by defult)
.start()
Start or resume the animation loop, emit the 'start' event
.stop()
Stops the animation loop, emit the 'stop' event