Clone a Line

Demonstrates how to create independent copies of a Line geometry object using the Clone method.

Clone a Line, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    lines;
    line;
    graphics;

    create ()
    {
        this.graphics = this.add.graphics({ lineStyle: { width: 4, color: 0xaa00aa, alpha: 0.6 } });

        this.line = new Phaser.Geom.Line(100, 300, 400, 300);

        this.lines = [];
    }

    update ()
    {
        Phaser.Geom.Line.Rotate(this.line, 0.03);

        this.lines.push(Phaser.Geom.Line.Clone(this.line));

        this.graphics.clear();

        this.graphics.strokeLineShape(this.line);

        for (let i = 0; i < this.lines.length; i++)
        {
            Phaser.Geom.Line.Offset(this.lines[i], 3, 0);

            if (this.lines[i].left > 800)
            {
                this.lines.splice(i--, 1);
            }
            else
            {
                this.graphics.strokeLineShape(this.lines[i]);
            }

        }

    }
}

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);

More in Line31 examples