Pixi Particles
A particle system library for the PixiJS library. Also, we created an interactive particle editor to design and preview custom particle emitters which utilitze PixiParticles.
Breaking changes in v3 from v2
- On
Emitter
, playOnce()
no longer sets autoUpdate
to true. Set it manually before use.
playOnceAndDestroy()
is unaffected. - On
Emitter
, start*
and end*
properties for alpha, color, scale, and speed have been
replaced by a singly linked list of PropertyNode
objects. - Dropped support for PIXI v3. Please use v4 or v5.
Sample Usage
Please see the examples for various pre-made particle configurations.
var emitter = new PIXI.particles.Emitter(
container,
[PIXI.Texture.fromImage('image.jpg')],
{
alpha: {
list: [
{
value: 0.8,
time: 0
},
{
value: 0.1,
time: 1
}
],
isStepped: false
},
scale: {
list: [
{
value: 1,
time: 0
},
{
value: 0.3,
time: 1
}
],
isStepped: false
},
color: {
list: [
{
value: "fb1010",
time: 0
},
{
value: "f5b830",
time: 1
}
],
isStepped: false
},
speed: {
list: [
{
value: 200,
time: 0
},
{
value: 100,
time: 1
}
],
isStepped: false
},
startRotation: {
min: 0,
max: 360
},
rotationSpeed: {
min: 0,
max: 0
},
lifetime: {
min: 0.5,
max: 0.5
},
frequency: 0.008,
spawnChance: 1,
particlesPerWave: 1,
emitterLifetime: 0.31,
maxParticles: 1000,
pos: {
x: 0,
y: 0
},
addAtBack: false,
spawnType: "circle",
spawnCircle: {
x: 0,
y: 0,
r: 10
}
}
);
var elapsed = Date.now();
var update = function(){
requestAnimationFrame(update);
var now = Date.now();
emitter.update((now - elapsed) * 0.001);
elapsed = now;
};
emitter.emit = true;
update();
Note on Emitter Cleanup
When using PixiJS 3 or 4, the SpriteRenderer in WebGL may keep a reference to your particles after you have destroyed your emitter. To ensure that they are garbage collected, in WebGL only, reset the SpriteRenderer's sprite batching with yourRenderer.plugins.sprite.sprites.length = 0;
. This is not needed in PixiJS 5.
Documentation
http://pixijs.github.io/pixi-particles/docs/
Installation
PixiParticles can be installed or NPM.
npm install pixi-particles
Examples
Typescript
You can use require to get the namespace for pixi-particles, or use a triple slash reference for using the PIXI.particles namespace.
import particles = require('pixi-particles');
let myEmitter:particles.Emitter = new particles.Emitter(myContainer);
require('pixi-particles');
let myEmitter:PIXI.particles.Emitter = new PIXI.particles.Emitter(myContainer);
Use in Haxe
Externs for Haxe have been added to adireddy's Pixi externs - these are out of date but may be updated in a fork.
Contributer Note
This project uses yarn
rather than npm
to take advantage of the workspaces feature for the tests, making it easier to have standalone tests that share dependencies where possible.
License
Copyright (c) 2015 CloudKid
Released under the MIT License.