Particle Gravity Well

Demonstrates how to use a Gravity Well to exert gravitational force on particles, attracting them toward a specific point in the scene.

Particle Gravity Well, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
        this.load.image('bg', 'assets/skies/darkstone.png');
        this.load.image('spark', 'assets/particles/elec3.png');
    }

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

        const emitter = this.add.particles(0, 0, 'spark', {
            scale: 0.5,
            lifespan: 10000,
            gravityY: -50,
            frequency: 20,
            maxVelocityX: 200,
            maxVelocityY: 200,
            blendMode: 'ADD'
        });

        const shape1 = new Phaser.Geom.Rectangle(0, 600, 800, 128);

        emitter.addEmitZone({ type: 'random', source: shape1 });

        emitter.createGravityWell({
            x: 400,
            y: 150,
            power: 4.2,
            epsilon: 250,
            gravity: 100
        });
    }
}

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