Filled Rectangles

Demonstrates how to draw filled rectangles using the Graphics object, including setting fill colors and alpha transparency.

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

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

        graphics.fillStyle(0xff0000, 0.5);
        graphics.fillRect(250, 200, 400, 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