Particle Emitter Custom Callbacks

Demonstrates how to use custom callback functions for particle emitter properties to dynamically update the emission coordinates based on user input.

Particle Emitter Custom Callbacks, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
        this.load.image('bg', 'assets/tweens/sky.png');
        this.load.atlas('match3', 'assets/atlas/match3.png', 'assets/atlas/match3.json');
    }

    create ()
    {
        this.add.image(400, 300, 'bg');

        let pointerX = 400;
        let pointerY = 300;

        this.input.on('pointerdown', pointer => {
            pointerX = pointer.worldX;
            pointerY = pointer.worldY;
        });

        this.add.particles(0, 0, 'match3', {
            x: () => {
                return pointerX;
            },
            y: () => {
                return pointerY;
            },
            frame: 'Match3_Icon_09',
            speed: 200,
            lifespan: 2000,
            gravityY: 200,
            scale: 0.5
        });

        this.add.text(10, 10, 'Click to set emission coordinates');
    }
}

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);

More in Particle Emitter44 examples