Marching Ants Rectangle
Demonstrates how to use the Marching Ants function to distribute a specific number of points or sprites evenly along the perimeter of a Rectangle geometry object.
800 × 600
class Example extends Phaser.Scene
{
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('chunk', 'assets/sprites/chunk.png');
}
create ()
{
const rect = new Phaser.Geom.Rectangle(100, 100, 300, 180);
// Each point is 10px apart
// var points = Phaser.Geom.Rectangle.MarchingAnts(rect, 10);
// In this version we get the points based on passing in a quantity of 64 points only
const points = Phaser.Geom.Rectangle.MarchingAnts(rect, false, 64);
for (let i = 0; i < points.length; i++)
{
this.add.image(points[i].x, points[i].y, 'chunk');
}
}
}
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);