pixi-timeout
v1.0.4
Published
Pixi.js plugin. A setTimeout replacement using PIXI.Ticker
Downloads
12
Maintainers
Readme
pixi-timeout
Pixi-timeout is a plugin which replicates the behaviour of window.setTimout but uses PIXI.Ticker (requestAnimationFrame) as the method for progressing time. The bonus is that any timeouts will be paused and resumed automatically when you call PIXI.Application.stop
& PIXI.Application.start
Install
npm i pixi-timeout
Usage
Importing
common.js
require('pixi.js')
require('pixi-timeout')
es6 modules
import pixi from 'pixi.js'
import pixiTimeout from 'pixi-timeout'
Basic usage.
Simply supply the time to wait in seconds and the function to call upon completion
PIXI.setTimeout(
2, // delay in seconds
callback // completion handler
)
Clear
There are 2 ways to clear a timeout. First the traditional way
const timer = PIXI.setTimeout(2,callback)
PIXI.clearTimeout(timer)
or more conviniently
const timer = PIXI.setTimeout(2,callback)
timer.clear()
Finish
You can finish a timer immediately, which will simply cancel the timer and fire the callback.
timer.finish()
Pause & Resume
If you are using PIXI.Application for instantiation then all current timers are automatically paused and resumed when PIXI.Application.stop
& PIXI.Application.start
are called. Which is great for keeping audio, tweens and timeouts synchronised.
import pix from ‘pixi,js’
import pixiTimeout from 'pixi-timeout'
const myApp = new PIXI.Application()
myApp.stop() // pause
myApp.start() //resume
FPS, Speed & Time
pixi-timeout calculates time based on the PIXI.ticker settings. It assumes 60fps is the desired rate and uses the deltaTime
value from last frame to this frame to determine the correct time progression. Additionally it uses the speed
value from the PIXI.ticker
, so if you wish to adjust the optimal fps you can do so by changing the PIXI.ticker value and pixi-timeout will adjust accordingly