skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    thanks to winner_joiner, for the help

    For Arcade phisics

    To crop the hit box of a sprite you can use the player.body.setSize(10,10); or player.body.setOffset(5, 0);

    For Matter phisics

    Use setBody({width:10, height:10}), or setRectangle

    Final result

    using setBody({width:10, height:10}) enter image description here


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search