Minus scale misaligns physics body

When I give a minus value as scale for a sprite with a physics body, the image seems to flip correctly, as if the origin is 0, although it is set to 0.5 (which is the default anyway). This means that the image and the physics body are no longer aligned.

See code below, this can be pasted straight into the sandbox - http://labs.phaser.io/edit.html

var config = {
    type: Phaser.AUTO,
    parent: 'phaser-example',
    physics: {
        default: "arcade",
        arcade: {
        gravity: { y: 200 },
        debug: true
        }
    },
    width: 800,
    height: 600,
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);

function preload ()
{
    this.load.image('piggy', 'assets/pics/pigchampagne.png');
}

function create ()
{
    var pig = this.add.sprite(200, 300, "piggy");
    pig.setOrigin(0.5);
    pig.setScale(-1);
    this.physics.world.enable([pig]);
    pig.body.setCollideWorldBounds(true);
}

Ah looks like this arcade doesn’t support rotation of physics bodies (How to rotate collision on game object?), I guess that probably applies to scale too.

Use instead

pig.setFlipY(true);

That’s perfect, thanks so much @samme :slight_smile:

1 Like