Drawing Filled Shapes with Graphics
Demonstrates how to use the Graphics object to draw solid and semi-transparent rectangles and triangles.
800 × 600
class Example extends Phaser.Scene
{
create ()
{
const graphics = this.add.graphics();
graphics.fillStyle(0xffff00, 1);
graphics.fillRect(100, 100, 256, 256);
graphics.fillStyle(0xff00ff, 0.5);
graphics.fillRect(300, 200, 256, 256);
graphics.fillStyle(0x00ff00, 1);
graphics.fillTriangle(200, 200, 400, 50, 500, 300);
}
}
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);