Physics.P2.Body#Body

new Body(game, sprite, x, y, mass)

The Physics Body is typically linked to a single Sprite and defines properties that determine how the physics body is simulated.
These properties affect how the body reacts to forces, what forces it generates on itself (to simulate friction), and how it reacts to collisions in the scene.
In most cases, the properties are used to simulate physical effects. Each body also has its own property values that determine exactly how it reacts to forces and collisions in the scene.
By default a single Rectangle shape is added to the Body that matches the dimensions of the parent Sprite. See addShape, removeShape, clearShapes to add extra shapes around the Body.
Note: When bound to a Sprite to avoid single-pixel jitters on mobile devices we strongly recommend using Sprite sizes that are even on both axis, i.e. 128x128 not 127x127.
Note: When a game object is given a P2 body it has its anchor x/y set to 0.5, so it becomes centered.

Parameters
Name Type Argument Default Description
game Phaser.Game

Game reference to the currently running game.

sprite Phaser.Sprite <optional>

The Sprite object this physics body belongs to.

x number <optional>
0

The x coordinate of this Body.

y number <optional>
0

The y coordinate of this Body.

mass number <optional>
1

The default mass of this Body (0 = static).

Source code: physics/p2/Body.js (Line 23)
doc_phaser
2017-02-14 11:01:53
Comments
Leave a Comment

Please login to continue.