Primitive Graphics Shapes

Demonstrates how to draw basic shapes using the Graphics object, including rectangles, circles, and ellipses with custom fill and line styles.

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

        graphics.lineStyle(4, 0x00ff00, 1);

        graphics.strokeRect(32, 32, 256, 256);

        graphics.fillStyle(0xff0000, 0.8);

        graphics.fillCircle(260, 260, 120);

        graphics.lineStyle(4, 0xff00ff, 1);

        graphics.strokeEllipse(400, 300, 200, 128);

        // graphics.setAlpha(0.5);
    }
}

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

const game = new Phaser.Game(config);

More in Graphics40 examples