Place Sprites on a Circular Arc
Distribute a collection of sprites along a specific segment of a circle using start and end angles with the PlaceOnCircle action.
800 × 600
class Example extends Phaser.Scene
{
constructor ()
{
super();
}
preload ()
{
this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
this.load.image('bg', 'assets/skies/darkstone.png');
this.load.image('tree', 'assets/sprites/skullcandle.png');
this.load.image('cave', 'assets/sprites/cave.png');
}
create ()
{
this.add.image(400, 300, 'bg');
const circle = new Phaser.Geom.Circle(400, 300, 220);
const trees = [];
for (let i = 0; i < 14; i++)
{
trees.push(this.add.image(0, 0, 'tree'));
}
// The starting angle
const startAngle = Phaser.Math.DegToRad(135);
// The end angle can overshoot 360 as required
const endAngle = Phaser.Math.DegToRad(425);
Phaser.Actions.PlaceOnCircle(trees, circle, startAngle, endAngle);
// Depth sort based on y value
trees.forEach(tree => {
tree.setDepth(tree.y);
});
this.add.image(400, 300, 'cave');
}
}
const config = {
scale: { mode: Phaser.Scale.FIT },
type: Phaser.AUTO,
width: 800,
height: 600,
backgroundColor: '#000000',
parent: 'game-container',
roundPixels: true,
scene: Example
};
const game = new Phaser.Game(config);