Group Set Velocity X

Demonstrates how to use the setVelocityX method on an Arcade Physics Group to apply an initial velocity with an incremental step value to all group members.

Group Set Velocity X, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
        this.load.image('ball', 'assets/demoscene/doc-ball.png');
    }

    create ()
    {
        const group = this.physics.add.group({
            key: 'ball',
            frameQuantity: 12,
            gridAlign: {
                x: 25,
                y: 25,
                width: 1,
                height: 12,
                cellWidth: 50,
                cellHeight: 50
            },
            bounceX: 1,
            collideWorldBounds: true
        });

        group.setVelocityX(200, 10);
    }
}

const config = {
    scale: { mode: Phaser.Scale.FIT },
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    parent: 'game-container',
    physics: {
        default: 'arcade',
        arcade: {
            debug: false,
            gravity: { y: 0 }
        }
    },
    scene: Example
};

const game = new Phaser.Game(config);

More in Arcade132 examples