Split Path Filled

Demonstrates how to draw and fill multiple separate shapes within a single Graphics path by using moveTo to start new sub-paths.

Split Path Filled, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    create ()
    {
        const graphics = this.add.graphics();

        graphics.fillStyle(0x00ff00, 1);

        graphics.beginPath();

        graphics.moveTo(200, 200);
        graphics.lineTo(300, 300);
        graphics.lineTo(200, 400);
        graphics.lineTo(200, 200);

        graphics.moveTo(500, 200);
        graphics.lineTo(600, 300);
        graphics.lineTo(500, 400);
        graphics.lineTo(500, 200);

        graphics.fillPath();
    }
}

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

const game = new Phaser.Game(config);

More in Primitives17 examples