In this fiddle, I’m trying to understand why the sprite in the red outline has some weird offset applied to it (image below)… I set the position the same way I set the position of the blue outline sprite, so what’s going on here? Does it have something to do with the center of mass? I could fix this by applying some arbitrary offset in the setPosition method, but I don’t know how I’d determine that offset.
class Example extends Phaser.Scene {
constructor() {
super();
}
preload() {
this.load.spritesheet("tiles", "https://i.imgur.com/FeCe8cx.png", {
frameWidth: 16,
frameHeight: 16,
spacing: 4,
});
}
create() {
const wallBottomLeft = this.matter.add.sprite(16, 16, "tiles", 13, {
isStatic: true,
ignoreGravity: true,
shape: {
type: "polygon",
},
vertices: [{
x: 0,
y: 0,
}, {
x: 16,
y: 0,
}, {
x: 16,
y: 16,
}, {
x: 0,
y: 8,
}],
render: {
lineColor: 0xFF0000,
},
});
wallBottomLeft.setPosition(wallBottomLeft.x + 8, wallBottomLeft.y + 8);
const wallBottom = this.matter.add.sprite(32, 16, "tiles", 14, {
isStatic: true,
ignoreGravity: true,
});
wallBottom.setPosition(wallBottom.x + 8, wallBottom.y + 8);
}
}
const config = {
type: Phaser.AUTO,
parent: "phaser-example",
zoom: 2,
pixelArt: true,
physics: {
default: "matter",
matter: {
debug: true,
},
},
scene: [Example],
width: 256,
height: 176,
scale: {
mode: Phaser.Scale.ScaleModes.HEIGHT_CONTROLS_WIDTH,
},
};
new Phaser.Game(config);