Physics.Arcade.Body#setSize()

setSize(width, height, offsetX, offsetY)

You can modify the size of the physics Body to be any dimension you need.
This allows you to make it smaller, or larger, than the parent Sprite.
You can also control the x and y offset of the Body. This is the position of the
Body relative to the top-left of the Sprite texture.

For example: If you have a Sprite with a texture that is 80x100 in size,
and you want the physics body to be 32x32 pixels in the middle of the texture, you would do:

setSize(32, 32, 24, 34)

Where the first two parameters is the new Body size (32x32 pixels).
24 is the horizontal offset of the Body from the top-left of the Sprites texture, and 34
is the vertical offset.

Calling setSize on a Body that has already had setCircle will reset all of the Circle
properties, making this Body rectangular again.

Parameters
Name Type Argument Description
width number

The width of the Body.

height number

The height of the Body.

offsetX number <optional>

The X offset of the Body from the top-left of the Sprites texture.

offsetY number <optional>

The Y offset of the Body from the top-left of the Sprites texture.

Source code: physics/arcade/Body.js (Line 1040)
doc_phaser
2017-02-14 10:59:41
Comments
Leave a Comment

Please login to continue.