Physics.P2.Body#setRectangle()

setRectangle(width, height, offsetX, offsetY, rotation) → {p2.Rectangle}

Clears any previously set shapes. The creates a new Rectangle shape at the given size and offset, and adds it to this Body.
If you wish to create a Rectangle to match the size of a Sprite or Image see Body.setRectangleFromSprite.
If this Body had a previously set Collision Group you will need to re-apply it to the new Shape this creates.

Parameters
Name Type Argument Default Description
width number <optional>
16

The width of the rectangle in pixels.

height number <optional>
16

The height of the rectangle in pixels.

offsetX number <optional>
0

Local horizontal offset of the shape relative to the body center of mass.

offsetY number <optional>
0

Local vertical offset of the shape relative to the body center of mass.

rotation number <optional>
0

Local rotation of the shape relative to the body center of mass, specified in radians.

Returns
p2.Rectangle -

The Rectangle shape that was added to the Body.

Source code: physics/p2/Body.js (Line 1228)
doc_phaser
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.