Larger Bounding Box

Shows how to increase an Arcade Physics body size beyond the sprite's texture dimensions and center the body on the object.

Larger Bounding Box, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
        this.load.image('atari', 'assets/sprites/atari130xe.png');
        this.load.image('mushroom', 'assets/sprites/mushroom2.png');
    }

    create ()
    {
        const atari = this.physics.add.image(200, 400, 'atari').setImmovable(true);

        //  In this example the new collision box is much larger than the original sprite

        //  220x104 original size, 300x400 new size, the 'true' argument means "center it on the gameobject"
        atari.setSize(300, 260, true);

        //  And this sprite will collide with it
        const mushroom1 = this.physics.add.image(700, 350, 'mushroom');
        const mushroom2 = this.physics.add.image(200, 50, 'mushroom');

        mushroom1.setVelocity(-100, 0);
        mushroom2.setVelocity(0, 100);

        this.physics.add.collider(atari, [ mushroom1, mushroom2 ]);
    }
}

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

const game = new Phaser.Game(config);

More in Arcade132 examples