Vector2 Clone
Demonstrates how to use the clone method to create copies of a Vector2 object, generating a sequence of unique points to define a path.
800 × 600
class Example extends Phaser.Scene
{
create ()
{
const graphics = this.add.graphics({ lineStyle: { width: 2, color: 0x2266aa } });
let point = new Phaser.Math.Vector2(400, 275);
const points = [];
let angle = 0;
let length = 1;
while (point.y < 600)
{
length += 0.05 / length;
angle += 0.05;
point = point.clone(); // Clone the point to avoid modifying the original
point.x += Math.cos(angle) * length;
point.y += Math.sin(angle) * length;
points.push(point);
}
graphics.strokePoints(points);
}
}
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);