Class: Body

Phaser.Physics.Arcade. Body

Arcade Physics Body Constructor

new Body(sprite)

The Physics Body is 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.

Parameters:
Name Type Description
sprite Phaser.Sprite

The Sprite object this physics body belongs to.

Source:

Members

acceleration

Properties:
Name Type Description
acceleration Phaser.Point

The acceleration in pixels per second sq. of the Body.

Source:

allowGravity

Properties:
Name Type Description
allowGravity boolean

Allow this Body to be influenced by the global Gravity value? Note: It will always be influenced by the local gravity if set.

Default Value:
  • true
Source:

allowRotation

Properties:
Name Type Description
allowRotation boolean

Allow angular rotation? This will cause the Sprite to be rotated via angularVelocity, etc.

Default Value:
  • true
Source:

angle

Properties:
Name Type Description
angle number

The angle of the Body based on its velocity in radians.

Source:

angularAcceleration

Properties:
Name Type Description
angularAcceleration number

The angular acceleration of the Body.

Default Value:
  • 0
Source:

angularDrag

Properties:
Name Type Description
angularDrag number

angularDrag is used to calculate friction on the body as it rotates.

Default Value:
  • 0
Source:

angularVelocity

Properties:
Name Type Description
angularVelocity number

The angular velocity of the Body.

Default Value:
  • 0
Source:

blocked

This object is populated with boolean values when the Body collides with the World bounds or a Tile. For example if blocked.up is true then the Body cannot move up.

Properties:
Name Type Description
blocked object

An object containing on which faces this Body is blocked from moving, if any.

Source:

<readonly> bottom

Properties:
Name Type Description
bottom number

The bottom-most point of this Body.

Source:

bounce

Properties:
Name Type Description
bounce Phaser.Point

The elasticitiy of the Body when colliding. This property determines how much energy a body maintains during a collision, i.e. its bounciness.

Source:

checkCollision

Set the checkCollision properties to control which directions collision is processed for this Body. For example checkCollision.up = false means it won't collide when the collision happened while moving up.

Properties:
Name Type Description
checkCollision object

An object containing allowed collision.

Source:

collideCallback

Properties:
Name Type Description
collideCallback function

If set this callback will be fired whenever this Body is hit (on any face). It will send three parameters, the face it hit on, this Body and the Body that hit it.

Default Value:
  • null
Source:

collideCallbackContext

Properties:
Name Type Description
collideCallbackContext object

The context in which the collideCallback is called.

Default Value:
  • null
Source:

collideWorldBounds

A Body can be set to collide against the World bounds automatically and rebound back into the World if this is set to true. Otherwise it will leave the World.

Properties:
Name Type Description
collideWorldBounds boolean

Should the Body collide with the World bounds?

Source:

<protected> contacts

Properties:
Name Type Description
contacts array.<Phaser.Physics.Arcade.Body>

Used to store references to bodies this Body is in contact with.

Source:

customSeparateCallback

Properties:
Name Type Description
customSeparateCallback function

If set this callback will be used for Body separation instead of the built-in one. Callback should return true if separated, otherwise false.

Default Value:
  • null
Source:

customSeparateContext

Properties:
Name Type Description
customSeparateContext object

The context in which the customSeparateCallback is called.

Default Value:
  • null
Source:

facing

Properties:
Name Type Description
facing number

A const reference to the direction the Body is traveling or facing.

Source:

game

Properties:
Name Type Description
game Phaser.Game

Local reference to game.

Source:

gravity

Properties:
Name Type Description
gravity Phaser.Point

The gravity applied to the motion of the Body. This works in addition to any gravity set on the world.

Source:

<readonly> height

Properties:
Name Type Description
height number

The current height of the Body, taking into account the point rotation.

Source:

immovable

Properties:
Name Type Description
immovable boolean

An immovable Body will not receive any impacts or exchanges of velocity from other bodies.

Default Value:
  • false
Source:

<readonly> left

Properties:
Name Type Description
left number

The left-most point of this Body.

Source:

linearDamping

Properties:
Name Type Description
linearDamping number

linearDamping is used to calculate friction on the body as it moves through the world. For example, this might be used to simulate air or water friction.

Default Value:
  • 0.0
Source:

mass

Properties:
Name Type Description
mass number

The mass property determines how forces affect the body, as well as how much momentum the body has when it is involved in a collision.

Default Value:
  • 1
Source:

maxAngular

Properties:
Name Type Description
maxAngular number

The maximum angular velocity that the Body can reach.

Default Value:
  • 1000
Source:

maxVelocity

Properties:
Name Type Description
maxVelocity Phaser.Point

The maximum velocity that the Body can reach.

Source:

minVelocity

Properties:
Name Type Description
minVelocity Phaser.Point

When a body rebounds off another body or a wall the minVelocity is checked. If the new velocity is lower than minVelocity the body is stopped.

Source:

moves

Properties:
Name Type Description
moves boolean

Set to true to allow the Physics system (such as velocity) to move this Body, or false to move it manually.

Default Value:
  • true
Source:

offset

Properties:
Name Type Description
offset Phaser.Point

The offset of the Physics Body from the Sprite x/y position.

Source:

<protected> overlapX

Properties:
Name Type Description
overlapX number

Mostly used internally to store the overlap values from Tile seperation.

Source:

<protected> overlapY

Properties:
Name Type Description
overlapY number

Mostly used internally to store the overlap values from Tile seperation.

Source:

polygon

Properties:
Name Type Description
polygon SAT.Polygon

The SAT Polygons, as derived from the Shape.

Source:

<readonly> preRotation

Properties:
Name Type Description
preRotation number

The previous rotation of the physics body.

Source:

<readonly> preX

Properties:
Name Type Description
preX number

The previous x position of the physics body.

Source:

<readonly> preY

Properties:
Name Type Description
preY number

The previous y position of the physics body.

Source:

rebound

Properties:
Name Type Description
rebound boolean

A Body set to rebound will exchange velocity with another Body during collision. Set to false to allow this body to be 'pushed' rather than exchange velocity.

Default Value:
  • true
Source:
Properties:
Name Type Description
right number

The right-most point of this Body.

Source:

rotation

Properties:
Name Type Description
rotation number

The amount the parent Sprite is rotated.

Default Value:
  • 0
Source:

shape

Properties:
Name Type Description
shape SAT.Box | SAT.Circle | SAT.Polygon

The SAT Collision shape.

Source:

speed

Properties:
Name Type Description
speed number

The speed in pixels per second sq. of the Body.

Source:

sprite

Properties:
Name Type Description
sprite Phaser.Sprite

Reference to the parent Sprite.

Source:

<readonly> top

Properties:
Name Type Description
top number

The top-most point of this Body.

Source:

touching

This object is populated with boolean values when the Body collides with another. touching.up = true means the collision happened to the top of this Body for example.

Properties:
Name Type Description
touching object

An object containing touching results.

Source:

type

Properties:
Name Type Description
type Phaser.Physics.Arcade.RECT | Phaser.Physics.Arcade.CIRCLE

The type of SAT Shape.

Source:

velocity

Properties:
Name Type Description
velocity Phaser.Point

The velocity of the Body.

Source:

<readonly> width

Properties:
Name Type Description
width number

The current width of the Body, taking into account the point rotation.

Source:

x

Properties:
Name Type Description
x number

The x coordinate of this Body.

Source:

y

Properties:
Name Type Description
y number

The y coordinate of this Body.

Source:

Methods

<protected> add(v)

Adds the given Vector to this Body.

Parameters:
Name Type Description
v SAT.Vector

The vector to add to this Body.

Source:

addContact(body) → {boolean}

Adds the given Body to the contact list of this Body. Also adds this Body to the contact list of the given Body.

Parameters:
Name Type Description
body Phaser.Physics.Arcade.Body

The Body to be added.

Source:
Returns:

True if the given Body was added to this contact list, false if already on it.

Type
boolean

<protected> applyDamping()

Internal method that checks the acceleration and applies damping if not set.

Source:

<protected> checkBlocked()

Internal method that checks and potentially resets the blocked status flags.

Source:

deltaX() → {number}

Returns the delta x value. The amount the Body has moved horizontally in the current step.

Source:
Returns:

The delta value. Positive if the motion was to the right, negative if to the left.

Type
number

deltaY() → {number}

Returns the delta y value. The amount the Body has moved vertically in the current step.

Source:
Returns:

The delta value. Positive if the motion was downwards, negative if upwards.

Type
number

deltaZ() → {number}

Returns the delta z value. The amount the Body has rotated in the current step.

Source:
Returns:

The delta value.

Type
number

destroy()

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

Source:

<protected> exchange(body)

Exchange velocity with the given Body.

Parameters:
Name Type Description
body Phaser.Physics.Arcade.Body

The Body that collided.

Source:

getDownwardForce() → {number}

Gets the total force being applied on the X axis, including gravity and velocity.

Source:
Returns:

The total force being applied on the Y axis.

Type
number

getUpwardForce() → {number}

Gets the total force being applied on the X axis, including gravity and velocity.

Source:
Returns:

The total force being applied on the X axis.

Type
number

<protected> give(body, response)

Separation response handler.

Parameters:
Name Type Description
body Phaser.Physics.Arcade.Body

The Body that collided.

response SAT.Response

The SAT Response object containing the collision data.

Source:

<protected> hitBottom(body, response)

Process a collision with the bottom face of this Body. Collision and separation can be further checked by setting a collideCallback. This callback will be sent 4 parameters: The face of collision, this Body, the colliding Body and the SAT Response. If the callback returns true then separation, rebounds and the touching flags will all be set. If it returns false this will be skipped and must be handled manually.

Parameters:
Name Type Description
body Phaser.Physics.Arcade.Body

The Body that collided.

response SAT.Response

The SAT Response object containing the collision data.

Source:

<protected> hitLeft(body, response)

Process a collision with the left face of this Body. Collision and separation can be further checked by setting a collideCallback. This callback will be sent 4 parameters: The face of collision, this Body, the colliding Body and the SAT Response. If the callback returns true then separation, rebounds and the touching flags will all be set. If it returns false this will be skipped and must be handled manually.

Parameters:
Name Type Description
body Phaser.Physics.Arcade.Body

The Body that collided.

response SAT.Response

The SAT Response object containing the collision data.

Source:

<protected> hitRight(body, response)

Process a collision with the right face of this Body. Collision and separation can be further checked by setting a collideCallback. This callback will be sent 4 parameters: The face of collision, this Body, the colliding Body and the SAT Response. If the callback returns true then separation, rebounds and the touching flags will all be set. If it returns false this will be skipped and must be handled manually.

Parameters:
Name Type Description
body Phaser.Physics.Arcade.Body

The Body that collided.

response SAT.Response

The SAT Response object containing the collision data.

Source:

<protected> hitTop(body, response)

Process a collision with the top face of this Body. Collision and separation can be further checked by setting a collideCallback. This callback will be sent 4 parameters: The face of collision, this Body, the colliding Body and the SAT Response. If the callback returns true then separation, rebounds and the touching flags will all be set. If it returns false this will be skipped and must be handled manually.

Parameters:
Name Type Description
body Phaser.Physics.Arcade.Body

The Body that collided.

response SAT.Response

The SAT Response object containing the collision data.

Source:

inContact(body) → {boolean}

Checks if this Body is already in contact with the given Body.

Parameters:
Name Type Description
body Phaser.Physics.Arcade.Body

The Body to be checked.

Source:
Returns:

True if the given Body is already in contact with this Body.

Type
boolean

<protected> integrateVelocity()

Internal method. Integrates velocity, global gravity and the delta timer.

Source:

onFloor() → {boolean}

Determines if this Body is 'on the floor', which means in contact with a Tile or World bounds, or other object that has set 'down' as blocked.

Source:
Returns:

True if this Body is 'on the floor', which means in contact with a Tile or World bounds, or object that has set 'down' as blocked.

Type
boolean

onWall() → {boolean}

Determins if this Body is 'on a wall', which means horizontally in contact with a Tile or World bounds, or other object but not the ground.

Source:
Returns:

True if this Body is 'on a wall', which means horizontally in contact with a Tile or World bounds, or other object but not the ground.

Type
boolean

overlap(body, response) → {boolean}

Checks for an overlap between this Body and the given Body.

Parameters:
Name Type Description
body Phaser.Physics.Arcade.Body

The Body that is being checked against this Body.

response SAT.Response

SAT Response handler.

Source:
Returns:

True if the two bodies overlap, otherwise false.

Type
boolean

<protected> postUpdate()

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

Source:

<protected> preUpdate()

Internal method that updates the Body position in relation to the parent Sprite.

Source:

<protected> processRebound(body)

Rebound the velocity of this Body.

Parameters:
Name Type Description
body Phaser.Physics.Arcade.Body

The Body that collided.

Source:

<protected> reboundCheck(x, y, rebound)

Check if we're below minVelocity and gravity isn't trying to drag us in the opposite direction.

Parameters:
Name Type Description
x boolean

Check the X axis?

y boolean

Check the Y axis?

rebound boolean

If true it will reverse the velocity on the given axis

Source:

removeContact(body) → {boolean}

Removes the given Body from the contact list of this Body. Also removes this Body from the contact list of the given Body.

Parameters:
Name Type Description
body Phaser.Physics.Arcade.Body

The Body to be removed.

Source:
Returns:

True if the given Body was removed from this contact list, false if wasn't on it.

Type
boolean

reset(full)

Resets the Body motion values: velocity, acceleration, angularVelocity and angularAcceleration. Also resets the forces to defaults: gravity, bounce, minVelocity,maxVelocity, angularDrag, maxAngular, mass, friction and checkCollision if 'full' specified.

Parameters:
Name Type Argument Default Description
full boolean <optional>
false

A full reset clears down settings you may have set, such as gravity, bounce and drag. A non-full reset just clears motion values.

Source:

<protected> separate(body, response) → {boolean}

This separates this Body from the given Body unless a customSeparateCallback is set. It assumes they have already been overlap checked and the resulting overlap is stored in the SAT response.

Parameters:
Name Type Description
body Phaser.Physics.Arcade.Body

The Body to be separated from this one.

response SAT.Response

SAT Response handler.

Source:
Returns:

True if the bodies were separated, false if not (for example checkCollide allows them to pass through)

Type
boolean

setCircle(radius, offsetX, offsetY)

Sets this Body to use a circle of the given radius for all collision. The Circle will be centered on the center of the Sprite by default, but can be adjusted via the Body.offset property and the setCircle x/y parameters.

Parameters:
Name Type Argument Default Description
radius number

The radius of this circle (in pixels)

offsetX number <optional>
0

The x amount the circle will be offset from the Sprites center.

offsetY number <optional>
0

The y amount the circle will be offset from the Sprites center.

Source:

setPolygon(points)

Sets this Body to use a convex polygon for collision. The points are specified in a counter-clockwise direction and must create a convex polygon. Use Body.translate and/or Body.offset to re-position the polygon from the Sprite origin.

Parameters:
Name Type Description
points Array.<SAT.Vector> | Array.<number> | SAT.Vector | number

This can be an array of Vectors that form the polygon, a flat array of numbers that will be interpreted as [x,y, x,y, ...], or the arguments passed can be all the points of the polygon e.g. setPolygon(new SAT.Vector(), new SAT.Vector(), ...), or the arguments passed can be flat x,y values e.g. setPolygon(x,y, x,y, x,y, ...) where x and y are Numbers.

Source:

setRectangle(width, height, translateX, translateY)

Sets this Body to use a rectangle for all collision. If you don't specify any parameters it will be sized to match the parent Sprites current width and height (including scale factor) and centered on the sprite.

Parameters:
Name Type Argument Description
width number <optional>

The width of the rectangle. If not specified it will default to the width of the parent Sprite.

height number <optional>

The height of the rectangle. If not specified it will default to the height of the parent Sprite.

translateX number <optional>

The x amount the rectangle will be translated from the Sprites center.

translateY number <optional>

The y amount the rectangle will be translated from the Sprites center.

Source:

<protected> split(body, response)

Split the collision response evenly between the two bodies.

Parameters:
Name Type Description
body Phaser.Physics.Arcade.Body

The Body that collided.

response SAT.Response

The SAT Response object containing the collision data.

Source:

<protected> sub(v)

Subtracts the given Vector from this Body.

Parameters:
Name Type Description
v SAT.Vector

The vector to substract from this Body.

Source:

<protected> take(body, response)

Separation response handler.

Parameters:
Name Type Description
body Phaser.Physics.Arcade.Body

The Body that collided.

response SAT.Response

The SAT Response object containing the collision data.

Source:

translate(x, y)

Used for translating rectangle and polygon bodies from the Sprite parent. Doesn't apply to Circles. See also the Body.offset property.

Parameters:
Name Type Description
x number

The x amount the polygon or rectangle will be translated by from the Sprite.

y number

The y amount the polygon or rectangle will be translated by from the Sprite.

Source:

<protected> updateBounds()

Internal method that updates the left, right, top, bottom, width and height properties.

Source:

<protected> updateScale()

Internal method that updates the Body scale in relation to the parent Sprite.

Source:
Phaser Copyright © 2012-2014 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.0-dev on Sat Feb 08 2014 07:19:48 GMT-0000 (GMT) using the DocStrap template.