Search code examples
htmlgame-developmentphaser-framework

Issue using sprite, extra margin in character sprite


when i load player character in Phaser.js using matter physics there's a extra margin. Is there a way to remove it using Phaser.js or i will need to update the image directly.

enter image description here


Solution

  • If you just want to change the size, because of physics collisions, you can simply use the function setSize of the Body object. (link to the documentation)

    And with setOffset you can move the collision box, to the correct position. (link to the documentation)

    player.body.setSize(10,10); 
    player.body.setOffset(5, 0);
    

    Here you can find an official example with a static body, where the collision box is been made larger, with the same function.