Rectangle Fill and Gradient

Demonstrates how to draw filled rectangles using solid colors and multi-color gradients with the Graphics object.

Rectangle Fill and Gradient, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    create ()
    {
        var graphics = this.add.graphics();

        graphics.fillStyle(0x00ff00);
        graphics.fillRect(100, 100, 256, 256);

        graphics.fillGradientStyle(0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 1);
        graphics.fillRect(350, 300, 256, 256);
    }
}

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