Single Point Light

Demonstrates how to enable the 2D lighting system, use a normal-mapped texture, and add an animated point light to a scene.

Single Point Light, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
        this.load.image('brick', [ 'assets/normal-maps/brick.jpg', 'assets/normal-maps/brick_n.png' ]);
        this.load.image('logo', 'assets/sprites/atari130xe.png');
    }

    create ()
    {
        this.add.image(400, 300, 'brick').setLighting(true);

        this.add.image(400, 300, 'logo');

        this.lights.enable().setAmbientColor(0x555555);

        const hsv = Phaser.Display.Color.HSVColorWheel();

        const radius = 80;
        const intensity = 6;
        const x = radius;
        const y = 0;

        const color = hsv[10].color;

        const light = this.lights.addLight(400, y, radius, color, intensity);

        this.tweens.add({
            targets: light,
            y: 600,
            yoyo: true,
            repeat: -1,
            ease: 'Sine.easeInOut',
            duration: 2000
        });
    }
}

const config = {
    scale: { mode: Phaser.Scale.FIT },
    type: Phaser.WEBGL,
    width: 800,
    height: 600,
    parent: 'game-container',
    backgroundColor: '#000000',
    scene: Example
};

const game = new Phaser.Game(config);

More in Lights20 examples