SetSize() for StaticImage

I need a StaticImage as a platform and I need to SetSize it :

  • to make new collision box smaller than the original sprite
  • to “center it on the gameobject”
    What is the best way, please ?

I used this SetSize() : https://github.com/photonstorm/phaser/blob/v3.16.0/src/physics/arcade/StaticBody.js#L514

Example : https://codepen.io/Tonio24100/pen/MLEzNd

Seems best to position the body manually and then use body.setSize(…).

https://codepen.io/samme/pen/bzYrpj?editors=0010

1 Like

Perfect answer ! Thank you very much. And I saw you’ve alredy opened an issue.
Sorry to not have find your last posts in the forum and issues…
I will try to do better :star_struck:

1 Like

So now I think you can get consistent results this way:

staticBody.setSize(w, h, 0, 0).setOffset(x, y)

https://codepen.io/samme/pen/orgxjy

3 Likes

Love this solution. This will help me as well with some collision modification I’ll be making.

StaticBody#setSize arguments have changed in v3.18.0.

1 Like

Thanks for coming back to this and updating it, Samme