liabru / matter-js

a 2D rigid body physics engine for the web ▲● ■
MIT License
16.71k stars 1.96k forks source link

[Phaser 3] Position of matter sprite's image not correct in container #1279

Open hongha1412 opened 7 months ago

hongha1412 commented 7 months ago

Hi folks, Im developing a side scrolling game using phaser 3 and matter js as physics engine Currently im facing an issue:

For example:

// Assume that x = 100, y =100
const container = new CharacterContainer(scene, x, y);
const hat = new Hat(scene, 0, 0, texture); // Hat extends Phaser.Physics.Matter.Sprite, the second and third parameter is x and y position of it and relative to above container's position
container.add(hat);

With above code, after add body into container, the hat's image will display at (100, 100) of scene, but the physics body's position is at (0, 0) of scene

I have tried several methods to set offset of render image / physics body but all of them not works. Is there anyway to match matter physics body position with its sprite image position?

Calcue-dev commented 6 months ago

Do you have a codepen or something?