Basic Polygon
How to create a Polygon geometry object from an array of coordinates and render it using Graphics.
800 × 600
class Example extends Phaser.Scene
{
create ()
{
const polygon = new Phaser.Geom.Polygon([
400, 100,
200, 278,
340, 430,
650, 80
]);
const graphics = this.add.graphics({ x: 0, y: 0 });
graphics.lineStyle(2, 0x00aa00);
graphics.beginPath();
graphics.moveTo(polygon.points[0].x, polygon.points[0].y);
for (let i = 1; i < polygon.points.length; i++)
{
graphics.lineTo(polygon.points[i].x, polygon.points[i].y);
}
graphics.closePath();
graphics.strokePath();
}
}
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);