# Class: Body

## Phaser .Physics .P2. Body

Physics Body Constructor

#### 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.

  ##### 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:
    - physics/p2/Body.js, line 23

### Members

#### <static> DYNAMIC :Number

  Dynamic body.

  ##### Type:

  - Number

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `DYNAMIC` |  |

  Source:
    - physics/p2/Body.js, line 1289

#### <static> KINEMATIC :Number

  Kinematic body.

  ##### Type:

  - Number

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `KINEMATIC` |  |

  Source:
    - physics/p2/Body.js, line 1305

#### <static> STATIC :Number

  Static body.

  ##### Type:

  - Number

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `STATIC` |  |

  Source:
    - physics/p2/Body.js, line 1297

#### allowSleep

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `allowSleep` | boolean | -

  Source:
    - physics/p2/Body.js, line 1402

#### angle

  The angle of the Body in degrees from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement Body.angle = 450 is the same as Body.angle = 90. If you wish to work in radians instead of degrees use the property Body.rotation instead. Working in radians is faster as it doesn't have to convert values.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `angle` | number | The angle of this Body in degrees.

  Source:
    - physics/p2/Body.js, line 1425

#### angularDamping

  Damping is specified as a value between 0 and 1, which is the proportion of velocity lost per second.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `angularDamping` | number | The angular damping acting acting on the body.

  Source:
    - physics/p2/Body.js, line 1449

#### angularForce

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `angularForce` | number | The angular force acting on the body.

  Source:
    - physics/p2/Body.js, line 1470

#### angularVelocity

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `angularVelocity` | number | The angular velocity of the body.

  Source:
    - physics/p2/Body.js, line 1490

#### collidesWith

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `collidesWith` | array | Array of CollisionGroups that this Bodies shapes collide with.

  Source:
    - physics/p2/Body.js, line 95

#### collideWorldBounds

  A Body can be set to collide against the World bounds automatically if this is set to true. Otherwise it will leave the World. Note that this only applies if your World has bounds! The response to the collision should be managed via CollisionMaterials.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `collideWorldBounds` | boolean | Should the Body collide with the World bounds?

  Source:
    - physics/p2/Body.js, line 1748

#### damping

  Damping is specified as a value between 0 and 1, which is the proportion of velocity lost per second.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `damping` | number | The linear damping acting on the body in the velocity direction.

  Source:
    - physics/p2/Body.js, line 1510

#### <protected> data

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `data` | p2.Body | The p2 Body data.

  Source:
    - physics/p2/Body.js, line 59

#### debug

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `debug` | boolean | Enable or disable debug drawing of this body

  Source:
    - physics/p2/Body.js, line 1719

#### debugBody

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `debugBody` | Phaser.Physics.P2.BodyDebug | Reference to the debug body.

  Source:
    - physics/p2/Body.js, line 105

#### dynamic

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `dynamic` | boolean | Returns true if the Body is dynamic. Setting Body.dynamic to 'false' will make it static.

  Source:
    - physics/p2/Body.js, line 1340

#### fixedRotation

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `fixedRotation` | boolean | -

  Source:
    - physics/p2/Body.js, line 1531

#### force

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `force` | Phaser.InversePointProxy | The force applied to the body.

  Source:
    - physics/p2/Body.js, line 71

#### game

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `game` | Phaser.Game | Local reference to game.

  Source:
    - physics/p2/Body.js, line 33

#### gravity

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `gravity` | Phaser.Point | A locally applied gravity force to the Body. Applied directly before the world step. NOTE: Not currently implemented.

  Source:
    - physics/p2/Body.js, line 76

#### <readonly> id

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `id` | number | The Body ID. Each Body that has been added to the World has a unique ID.

  Source:
    - physics/p2/Body.js, line 1704

#### inertia

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `inertia` | number | The inertia of the body around the Z axis..

  Source:
    - physics/p2/Body.js, line 1554

#### kinematic

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `kinematic` | boolean | Returns true if the Body is kinematic. Setting Body.kinematic to 'false' will make it static.

  Source:
    - physics/p2/Body.js, line 1373

#### mass

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `mass` | number | -

  Source:
    - physics/p2/Body.js, line 1574

#### motionState

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `motionState` | number | The type of motion this body has. Should be one of: Body.STATIC (the body does not move), Body.DYNAMIC (body can move and respond to collisions) and Body.KINEMATIC (only moves according to its .velocity).

  Source:
    - physics/p2/Body.js, line 1598

#### offset

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `offset` | Phaser.Point | The offset of the Physics Body from the Sprite x/y position.

  Source:
    - physics/p2/Body.js, line 53

#### onBeginContact

  Dispatched when a first contact is created between shapes in two bodies. This event is fired during the step, so collision has already taken place. The event will be sent 4 parameters: The body it is in contact with, the shape from this body that caused the contact, the shape from the contact body and the contact equation data array.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `onBeginContact` | Phaser.Signal |

  Source:
    - physics/p2/Body.js, line 83

#### onEndContact

  Dispatched when contact ends between shapes in two bodies. This event is fired during the step, so collision has already taken place. The event will be sent 3 parameters: The body it is in contact with, the shape from this body that caused the contact and the shape from the contact body.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `onEndContact` | Phaser.Signal |

  Source:
    - physics/p2/Body.js, line 90

#### removeNextStep

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `removeNextStep` | boolean | To avoid deleting this body during a physics step, and causing all kinds of problems, set removeNextStep to true to have it removed in the next preUpdate.

  Source:
    - physics/p2/Body.js, line 100

#### rotation

  The angle of the Body in radians. If you wish to work in degrees instead of radians use the Body.angle property instead. Working in radians is faster as it doesn't have to convert values.

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `rotation` | number | The angle of this Body in radians.

  Source:
    - physics/p2/Body.js, line 1621

#### sleepSpeedLimit

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `sleepSpeedLimit` | number | .

  Source:
    - physics/p2/Body.js, line 1644

#### sprite

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `sprite` | Phaser.Sprite | Reference to the parent Sprite.

  Source:
    - physics/p2/Body.js, line 43

#### static

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `static` | boolean | Returns true if the Body is static. Setting Body.static to 'false' will make it dynamic.

  Source:
    - physics/p2/Body.js, line 1307

#### type

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `type` | number | The type of physics system this body belongs to.

  Source:
    - physics/p2/Body.js, line 48

#### velocity

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `velocity` | Phaser.InversePointProxy | The velocity of the body. Set velocity.x to a negative value to move to the left, position to the right. velocity.y negative values move up, positive move down.

  Source:
    - physics/p2/Body.js, line 66

#### world

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `world` | Phaser.Physics.P2 | Local reference to the P2 World.

  Source:
    - physics/p2/Body.js, line 38

#### x

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `x` | number | The x coordinate of this Body.

  Source:
    - physics/p2/Body.js, line 1664

#### y

  ##### Properties:

  Name | Type | Description
  --- | --- | ---
  `y` | number | The y coordinate of this Body.

  Source:
    - physics/p2/Body.js, line 1684

### Methods

#### addCapsule(length, radius, offsetX, offsetY, rotation) → {p2.Capsule}

  Adds a Capsule shape to this Body. You can control the offset from the center of the body and the rotation.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `length` | number |  |  | The distance between the end points in pixels.
  `radius` | number |  |  | Radius of the capsule in radians.
  `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.

  Source:
    - physics/p2/Body.js, line 903

  ##### Returns:

  The Capsule shape that was added to the Body.

  Type
    p2.Capsule

#### addCircle(radius, offsetX, offsetY, rotation) → {p2.Circle}

  Adds a Circle shape to this Body. You can control the offset from the center of the body and the rotation.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `radius` | number |  |  | The radius of this circle (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.

  Source:
    - physics/p2/Body.js, line 812

  ##### Returns:

  The Circle shape that was added to the Body.

  Type
    p2.Circle

#### addFixture(fixtureData) → {array}

  Add a polygon fixture. This is used during #loadPolygon.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `fixtureData` | string | The data for the fixture. It contains: isSensor, filter (collision) and the actual polygon shapes.

  Source:
    - physics/p2/Body.js, line 1133

  ##### Returns:

  An array containing the generated shapes for the given polygon.

  Type
    array

#### addLine(length, offsetX, offsetY, rotation) → {p2.Line}

  Adds a Line shape to this Body. The line shape is along the x direction, and stretches from [-length/2, 0] to [length/2,0]. You can control the offset from the center of the body and the rotation.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `length` | number |  |  | The length of this line (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.

  Source:
    - physics/p2/Body.js, line 883

  ##### Returns:

  The Line shape that was added to the Body.

  Type
    p2.Line

#### addParticle(offsetX, offsetY, rotation) → {p2.Particle}

  Adds a Particle shape to this Body. You can control the offset from the center of the body and the rotation.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `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.

  Source:
    - physics/p2/Body.js, line 866

  ##### Returns:

  The Particle shape that was added to the Body.

  Type
    p2.Particle

#### addPhaserPolygon(key, object)

  Reads the shape data from a physics data file stored in the Game.Cache and adds it as a polygon to this Body. The shape data format is based on the custom phaser export in.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `key` | string | The key of the Physics Data file as stored in Game.Cache.
  `object` | string | The key of the object within the Physics data file that you wish to load the shape data from.

  Source:
    - physics/p2/Body.js, line 1096

#### addPlane(offsetX, offsetY, rotation) → {p2.Plane}

  Adds a Plane shape to this Body. The plane is facing in the Y direction. You can control the offset from the center of the body and the rotation.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `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.

  Source:
    - physics/p2/Body.js, line 849

  ##### Returns:

  The Plane shape that was added to the Body.

  Type
    p2.Plane

#### addPolygon(options, points) → {boolean}

  Reads a polygon shape path, and assembles convex shapes from that and puts them at proper offset points. The shape must be simple and without holes. This function expects the x.y values to be given in pixels. If you want to provide them at p2 world scales then call Body.data.fromPolygon directly.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---

  `options`

  object

  An object containing the build options:

  ###### Properties

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `optimalDecomp` | boolean | <optional> | false | Set to true if you need optimal decomposition. Warning: very slow for polygons with more than 10 vertices.
  `skipSimpleCheck` | boolean | <optional> | false | Set to true if you already know that the path is not intersecting itself.
  `removeCollinearPoints` | boolean | number | <optional> | false | Set to a number (angle threshold value) to remove collinear points, or false to keep all points.

  `points` | Array.<number> | number | An array of 2d vectors that form the convex or concave polygon. Either [[0,0], [0,1],...] or a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arguments passed can be flat x,y values e.g. `setPolygon(options, x,y, x,y, x,y, ...)` where `x` and `y` are numbers.

  Source:
    - physics/p2/Body.js, line 923

  ##### Returns:

  True on success, else false.

  Type
    boolean

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

  Adds a Rectangle shape to this Body. You can control the offset from the center of the body and the rotation.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `width` | number |  |  | The width of the rectangle in pixels.
  `height` | number |  |  | 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.

  Source:
    - physics/p2/Body.js, line 830

  ##### Returns:

  The Rectangle shape that was added to the Body.

  Type
    p2.Rectangle

#### addShape(shape, offsetX, offsetY, rotation) → {p2.Shape}

  Add a shape to the body. You can pass a local transform when adding a shape, so that the shape gets an offset and an angle relative to the body center of mass. Will automatically update the mass properties and bounding radius.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `shape` | p2.Shape |  |  | The shape to add to the body.
  `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.

  Source:
    - physics/p2/Body.js, line 788

  ##### Returns:

  The shape that was added to the body.

  Type
    p2.Shape

#### addToWorld()

  Adds this physics body to the world.

  Source:
    - physics/p2/Body.js, line 715

#### adjustCenterOfMass()

  Moves the shape offsets so their center of mass becomes the body center of mass.

  Source:
    - physics/p2/Body.js, line 395

#### applyDamping(dt)

  Apply damping, see http://code.google.com/p/bullet/issues/detail?id=74 for details.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `dt` | number | Current time step.

  Source:
    - physics/p2/Body.js, line 406

#### applyForce(force, worldX, worldY)

  Apply force to a world point. This could for example be a point on the RigidBody surface. Applying force this way will add to Body.force and Body.angularForce.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `force` | number | The force to add.
  `worldX` | number | The world x point to apply the force on.
  `worldY` | number | The world y point to apply the force on.

  Source:
    - physics/p2/Body.js, line 418

#### clearCollision(clearGroup, clearMask, shape)

  Clears the collision data from the shapes in this Body. Optionally clears Group and/or Mask.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `clearGroup` | boolean | <optional> | true | Clear the collisionGroup value from the shape/s?
  `clearMask` | boolean | <optional> | true | Clear the collisionMask value from the shape/s?
  `shape` | p2.Shape | <optional> |  | An optional Shape. If not provided the collision data will be cleared from all Shapes in this Body.

  Source:
    - physics/p2/Body.js, line 295

#### clearShapes()

  Removes all Shapes from this Body.

  Source:
    - physics/p2/Body.js, line 770

#### collides(group, callback, callbackContext, shape)

  Adds the given CollisionGroup, or array of CollisionGroups, to the list of groups that this body will collide with and updates the collision masks.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `group` | Phaser.Physics.CollisionGroup | array |  | The Collision Group or Array of Collision Groups that this Bodies shapes will collide with.
  `callback` | function | <optional> | Optional callback that will be triggered when this Body impacts with the given Group.
  `callbackContext` | object | <optional> | The context under which the callback will be called.
  `shape` | p2.Shape | <optional> | An optional Shape. If not provided the collision mask will be added to all Shapes in this Body.

  Source:
    - physics/p2/Body.js, line 340

#### createBodyCallback(object, callback, callbackContext)

  Sets a callback to be fired any time a shape in this Body impacts with a shape in the given Body. The impact test is performed against body.id values. The callback will be sent 4 parameters: This body, the body that impacted, the Shape in this body and the shape in the impacting body. Note that the impact event happens after collision resolution, so it cannot be used to prevent a collision from happening. It also happens mid-step. So do not destroy a Body during this callback, instead set safeDestroy to true so it will be killed on the next preUpdate.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `object` | Phaser.Sprite | Phaser.TileSprite | Phaser.Physics.P2.Body | p2.Body | The object to send impact events for.
  `callback` | function | The callback to fire on impact. Set to null to clear a previously set callback.
  `callbackContext` | object | The context under which the callback will fire.

  Source:
    - physics/p2/Body.js, line 152

#### createGroupCallback(group, callback, callbackContext)

  Sets a callback to be fired any time this Body impacts with the given Group. The impact test is performed against shape.collisionGroup values. The callback will be sent 4 parameters: This body, the body that impacted, the Shape in this body and the shape in the impacting body. This callback will only fire if this Body has been assigned a collision group. Note that the impact event happens after collision resolution, so it cannot be used to prevent a collision from happening. It also happens mid-step. So do not destroy a Body during this callback, instead set safeDestroy to true so it will be killed on the next preUpdate.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `group` | Phaser.Physics.CollisionGroup | The Group to send impact events for.
  `callback` | function | The callback to fire on impact. Set to null to clear a previously set callback.
  `callbackContext` | object | The context under which the callback will fire.

  Source:
    - physics/p2/Body.js, line 192

#### destroy()

  Destroys this Body and all references it holds to other objects.

  Source:
    - physics/p2/Body.js, line 743

#### getCollisionMask() → {number}

  Gets the collision bitmask from the groups this body collides with.

  Source:
    - physics/p2/Body.js, line 219

  ##### Returns:

  The bitmask.

  Type
    number

#### loadData(key, object) → {boolean}

  DEPRECATED: This method will soon be removed from the API. Please avoid using. Reads the physics data from a physics data file stored in the Game.Cache. It will add the shape data to this Body, as well as set the density (mass).

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `key` | string | The key of the Physics Data file as stored in Game.Cache.
  `object` | string | The key of the object within the Physics data file that you wish to load the shape data from.

  Source:
    - physics/p2/Body.js, line 1257

  ##### Returns:

  True on success, else false.

  Type
    boolean

#### loadPolygon(key, object) → {boolean}

  Reads the shape data from a physics data file stored in the Game.Cache and adds it as a polygon to this Body.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `key` | string | The key of the Physics Data file as stored in Game.Cache.
  `object` | string | The key of the object within the Physics data file that you wish to load the shape data from.

  Source:
    - physics/p2/Body.js, line 1205

  ##### Returns:

  True on success, else false.

  Type
    boolean

#### moveBackward(speed)

  Moves the Body backwards based on its current angle and the given speed. The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `speed` | number | The speed at which it should move backwards.

  Source:
    - physics/p2/Body.js, line 545

#### moveDown(speed)

  If this Body is dynamic then this will move it down by setting its y velocity to the given speed. The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `speed` | number | The speed at which it should move down, in pixels per second.

  Source:
    - physics/p2/Body.js, line 635

#### moveForward(speed)

  Moves the Body forwards based on its current angle and the given speed. The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `speed` | number | The speed at which it should move forwards.

  Source:
    - physics/p2/Body.js, line 528

#### moveLeft(speed)

  If this Body is dynamic then this will move it to the left by setting its x velocity to the given speed. The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `speed` | number | The speed at which it should move to the left, in pixels per second.

  Source:
    - physics/p2/Body.js, line 596

#### moveRight(speed)

  If this Body is dynamic then this will move it to the right by setting its x velocity to the given speed. The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `speed` | number | The speed at which it should move to the right, in pixels per second.

  Source:
    - physics/p2/Body.js, line 609

#### moveUp(speed)

  If this Body is dynamic then this will move it up by setting its y velocity to the given speed. The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `speed` | number | The speed at which it should move up, in pixels per second.

  Source:
    - physics/p2/Body.js, line 622

#### <protected> postUpdate()

  Internal method. This is called directly before the sprites are sent to the renderer and after the update function has finished.

  Source:
    - physics/p2/Body.js, line 664

#### <protected> preUpdate()

  Internal method. This is called directly before the sprites are sent to the renderer and after the update function has finished.

  Source:
    - physics/p2/Body.js, line 648

#### removeFromWorld()

  Removes this physics body from the world.

  Source:
    - physics/p2/Body.js, line 729

#### removeShape(shape) → {boolean}

  Remove a shape from the body. Will automatically update the mass properties and bounding radius.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `shape` | p2.Circle | p2.Rectangle | p2.Plane | p2.Line | p2.Particle | The shape to remove from the body.

  Source:
    - physics/p2/Body.js, line 986

  ##### Returns:

  True if the shape was found and removed, else false.

  Type
    boolean

#### reset(x, y, resetDamping, resetMass)

  Resets the Body force, velocity (linear and angular) and rotation. Optionally resets damping and mass.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `x` | number |  |  | The new x position of the Body.
  `y` | number |  |  | The new x position of the Body.
  `resetDamping` | boolean | <optional> | false | Resets the linear and angular damping.
  `resetMass` | boolean | <optional> | false | Sets the Body mass back to 1.

  Source:
    - physics/p2/Body.js, line 682

#### rever(speed)

  Applies a force to the Body that causes it to 'thrust' backwards (in reverse), based on its current angle and the given speed. The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `speed` | number | The speed at which it should reverse.

  Source:
    - physics/p2/Body.js, line 579

#### rotateLeft(speed)

  This will rotate the Body by the given speed to the left (counter-clockwise).

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `speed` | number | The speed at which it should rotate.

  Source:
    - physics/p2/Body.js, line 504

#### rotateRight(speed)

  This will rotate the Body by the given speed to the left (clockwise).

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `speed` | number | The speed at which it should rotate.

  Source:
    - physics/p2/Body.js, line 516

#### setCircle(radius, offsetX, offsetY, rotation)

  Clears any previously set shapes. Then creates a new Circle shape and adds it to this Body.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `radius` | number |  |  | The radius of this circle (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.

  Source:
    - physics/p2/Body.js, line 999

#### setCollisionGroup(group, shape)

  Sets the given CollisionGroup to be the collision group for all shapes in this Body, unless a shape is specified. This also resets the collisionMask.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `group` | Phaser.Physics.CollisionGroup |  | The Collision Group that this Bodies shapes will use.
  `shape` | p2.Shape | <optional> | An optional Shape. If not provided the collision group will be added to all Shapes in this Body.

  Source:
    - physics/p2/Body.js, line 267

#### setMaterial(material, shape)

  Adds the given Material to all Shapes that belong to this Body. If you only wish to apply it to a specific Shape in this Body then provide that as the 2nd parameter.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `material` | Phaser.Physics.P2.Material |  | The Material that will be applied.
  `shape` | p2.Shape | <optional> | An optional Shape. If not provided the Material will be added to all Shapes in this Body.

  Source:
    - physics/p2/Body.js, line 1058

#### 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.

  ##### 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.

  Source:
    - physics/p2/Body.js, line 1016

  ##### Returns:

  The Rectangle shape that was added to the Body.

  Type
    p2.Rectangle

#### setRectangleFromSprite(sprite) → {p2.Rectangle}

  Clears any previously set shapes. Then creates a Rectangle shape sized to match the dimensions and orientation of the Sprite given. If no Sprite is given it defaults to using the parent of this Body.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `sprite` | Phaser.Sprite | Phaser.Image | <optional> | The Sprite on which the Rectangle will get its dimensions.

  Source:
    - physics/p2/Body.js, line 1039

  ##### Returns:

  The Rectangle shape that was added to the Body.

  Type
    p2.Rectangle

#### setZeroDamping()

  Sets the Body damping and angularDamping to zero.

  Source:
    - physics/p2/Body.js, line 466

#### setZeroForce()

  Sets the force on the body to zero.

  Source:
    - physics/p2/Body.js, line 432

#### setZeroRotation()

  If this Body is dynamic then this will zero its angular velocity.

  Source:
    - physics/p2/Body.js, line 443

#### setZeroVelocity()

  If this Body is dynamic then this will zero its velocity on both axis.

  Source:
    - physics/p2/Body.js, line 454

#### shapeChanged()

  Updates the debug draw if any body shapes change.

  Source:
    - physics/p2/Body.js, line 1082

#### thrust(speed)

  Applies a force to the Body that causes it to 'thrust' forwards, based on its current angle and the given speed. The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `speed` | number | The speed at which it should thrust.

  Source:
    - physics/p2/Body.js, line 562

#### toLocalFrame(out, worldPoint)

  Transform a world point to local body frame.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `out` | Float32Array | Array | The vector to store the result in.
  `worldPoint` | Float32Array | Array | The input world vector.

  Source:
    - physics/p2/Body.js, line 478

#### toWorldFrame(out, localPoint)

  Transform a local point to world frame.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `out` | Array | The vector to store the result in.
  `localPoint` | Array | The input local vector.

  Source:
    - physics/p2/Body.js, line 491

#### updateCollisionMask(shape)

  Updates the collisionMask.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `shape` | p2.Shape | <optional> | An optional Shape. If not provided the collision group will be added to all Shapes in this Body.

  Source:
    - physics/p2/Body.js, line 243