Vector2 Copy From

Demonstrates how to use the copy method to transfer coordinates from the pointer to a Vector2 object, creating a motion trail effect.

Vector2 Copy From, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    create ()
    {
        const graphics = this.add.graphics({ fillStyle: { color: 0x2266aa } });

        const points = [];

        for (let k = 0; k < 150; k++)
        {
            points.push(new Phaser.Math.Vector2());
        }

        let i = 0;

        this.input.on('pointermove', pointer =>
        {
            // const vector2 = points[i];
            points[i].copy(pointer);

            i = (i + 1) % points.length;

            graphics.clear();

            graphics.fillPointShape(pointer, 25);

            for (let j = 0; j < points.length; j++)
            {
                points[j].x += 4 + Math.abs(j - 75) / 15;

                graphics.fillPointShape(points[j], 25);
            }
        });
    }
}

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 Point18 examples