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
samme
February 6, 2019, 11:27pm
2
Seems best to position the body manually and then use body.setSize(…).
https://codepen.io/samme/pen/bzYrpj?editors=0010
I was wondering why there’s a difference between the setSize and setOffset methods of dynamic and static bodies.
I was using a dynamic body on a sprite and figure I could try a static body since my sprite will not be moving, just colliding/overlapping. An then I run into these differences, for example my sprite is a coin (sort of) my player would collect, Im reducing the size of the body because it feels better than leaving it at the default (taking the size of the gameobject). Everything works…
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
samme
June 11, 2019, 8:30pm
4
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
Love this solution. This will help me as well with some collision modification I’ll be making.
samme
June 25, 2019, 2:57pm
6
StaticBody#setSize arguments have changed in v3.18.0.
Thanks for coming back to this and updating it, Samme