Simple Arcade Physics Body

A basic demonstration of creating an Arcade Physics body with velocity, gravity, and world boundary collision.

Simple Arcade Physics Body, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
        this.load.image('block', 'assets/sprites/block.png');
    }

    create ()
    {
        const block = this.physics.add.image(400, 100, 'block');

        block.setVelocity(100, 200);
        block.setBounce(1, 1);
        block.setCollideWorldBounds(true);
    }
}

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

const game = new Phaser.Game(config);

More in Arcade132 examples