Particle Emitter with Multiple Emit Zones
Demonstrates how to attach multiple geometric shapes as emit zones to a single particle emitter, constraining particle creation to the edges of various shapes.
800 × 600
class Example extends Phaser.Scene
{
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('bg', 'assets/skies/darkstone.png');
this.load.atlas('flares', 'assets/particles/flares.png', 'assets/particles/flares.json');
}
create ()
{
const shape1 = new Phaser.Geom.Circle(0, 0, 160);
const shape2 = new Phaser.Geom.Ellipse(0, 0, 500, 150);
const shape3 = new Phaser.Geom.Rectangle(-150, -150, 300, 300);
const shape4 = new Phaser.Geom.Line(-150, -150, 150, 150);
const shape5 = new Phaser.Geom.Triangle.BuildEquilateral(0, -140, 300);
const emitter = this.add.particles(400, 300, 'flares', {
frame: { frames: [ 'red', 'green', 'blue', 'white', 'yellow' ], cycle: true },
blendMode: 'ADD',
lifespan: 500,
quantity: 4,
scale: { start: 0.5, end: 0.1 }
});
emitter.addEmitZone({ type: 'edge', source: shape1, quantity: 64, total: 1 });
emitter.addEmitZone({ type: 'edge', source: shape2, quantity: 64, total: 1 });
emitter.addEmitZone({ type: 'edge', source: shape3, quantity: 64, total: 1 });
emitter.addEmitZone({ type: 'edge', source: shape4, quantity: 64, total: 1 });
emitter.addEmitZone({ type: 'edge', source: shape5, quantity: 64, total: 1 });
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#000',
parent: 'game-container',
scene: Example
};
const game = new Phaser.Game(config);