Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Physics . Arcade . Body

This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Physics . Arcade . Body

A Dynamic Arcade Body.

Its static counterpart is Phaser.Physics.Arcade.StaticBody.

Constructor:

new Body(world, gameObject)

Parameters:

name type description
world Phaser.Physics.Arcade.World

The Arcade Physics simulation this Body belongs to.

gameObject Phaser.GameObjects.GameObject

The Game Object this Body belongs to.

Since: 3.0.0

Members

<private> _bounds: Phaser.Geom.Rectangle
Focus
Focus

Description:

Stores the Game Object's bounds.

Type:
Since: 3.0.0
Focus
Focus
<private> _dx: number
Focus
Focus

Description:

The calculated change in the Body's horizontal position during the last step.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
<private> _dy: number
Focus
Focus

Description:

The calculated change in the Body's vertical position during the last step.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
<private> _sx: number
Focus
Focus

Description:

Cached horizontal scale of the Body's Game Object.

Type:
number
Since: 3.0.0
Focus
Focus
<private> _sy: number
Focus
Focus

Description:

Cached vertical scale of the Body's Game Object.

Type:
number
Since: 3.0.0
Focus
Focus
<private> _tx: number
Focus
Focus

Description:

The final calculated change in the Body's horizontal position as of postUpdate.

Type:
number
Default: 0
Since: 3.22.0
Focus
Focus
<private> _ty: number
Focus
Focus

Description:

The final calculated change in the Body's vertical position as of postUpdate.

Type:
number
Default: 0
Since: 3.22.0
Focus
Focus
acceleration: Phaser.Math.Vector2
Focus
Focus

Description:

The Body's change in velocity, in pixels per second squared.

Type:
Since: 3.0.0
Focus
Focus
allowDrag: boolean
Focus
Focus

Description:

Whether this Body's velocity is affected by its drag.

Type:
boolean
Default: true
Since: 3.0.0
Focus
Focus
allowGravity: boolean
Focus
Focus

Description:

Whether this Body's position is affected by gravity (local or world).

Type:
boolean
Default: true
Since: 3.0.0
Focus
Focus
allowRotation: boolean
Focus
Focus

Description:

Whether this Body's rotation is affected by its angular acceleration and angular velocity.

Type:
boolean
Default: true
Since: 3.0.0
Focus
Focus
angle: number
Focus
Focus

Description:

The calculated angle of this Body's velocity vector, in radians, during the last step.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
angularAcceleration: number
Focus
Focus

Description:

The Body's angular acceleration (change in angular velocity), in degrees per second squared.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
angularDrag: number
Focus
Focus

Description:

Loss of angular velocity due to angular movement, in degrees per second.

Angular drag is applied only when angular acceleration is zero.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
angularVelocity: number
Focus
Focus

Description:

The rate of change of this Body's rotation, in degrees per second.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus

Description:

Whether this Body is colliding with a Static Body, a tile, or the world boundary. In a collision with a Static Body, if this Body has zero velocity then embedded will be set instead.

Type:
Since: 3.0.0
Focus
Focus
<readonly> bottom: number
Focus
Focus

Description:

The bottom edge of this Body.

Type:
number
Since: 3.0.0
Focus
Focus

Description:

Rebound following a collision, relative to 1.

Type:
Since: 3.0.0
Focus
Focus

Description:

The center of the Body. The midpoint of its position (top-left corner) and its bottom-right corner.

Type:
Since: 3.0.0
Focus
Focus

Description:

Whether this Body is checked for collisions and for which directions. You can set checkCollision.none = true to disable collision checks.

Type:
Since: 3.0.0
Focus
Focus
collideWorldBounds: boolean
Focus
Focus

Description:

Whether this Body interacts with the world boundary.

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
customBoundsRectangle: Phaser.Geom.Rectangle
Focus
Focus

Description:

The rectangle used for world boundary collisions.

By default it is set to the world boundary rectangle. Or, if this Body was created by a Physics Group, then whatever rectangle that Group defined.

You can also change it by using the Body.setBoundsRectangle method.

Type:
Since: 3.20
Focus
Focus
customSeparateX: boolean
Focus
Focus

Description:

A flag disabling the default horizontal separation of colliding bodies. Pass your own collideCallback to the collider.

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
customSeparateY: boolean
Focus
Focus

Description:

A flag disabling the default vertical separation of colliding bodies. Pass your own collideCallback to the collider.

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
debugBodyColor: number
Focus
Focus

Description:

The color of this Body on the debug display.

Type:
number
Since: 3.0.0
Focus
Focus
debugShowBody: boolean
Focus
Focus

Description:

Whether the Body is drawn to the debug display.

Type:
boolean
Since: 3.0.0
Focus
Focus
debugShowVelocity: boolean
Focus
Focus

Description:

Whether the Body's velocity is drawn to the debug display.

Type:
boolean
Since: 3.0.0
Focus
Focus

Description:

The Body's absolute maximum change in position, in pixels per step.

Type:
Since: 3.0.0
Focus
Focus

Description:

When useDamping is false (the default), this is absolute loss of velocity due to movement, in pixels per second squared.

When useDamping is true, this is a damping multiplier between 0 and 1. A value of 0 means the Body stops instantly. A value of 0.01 mean the Body keeps 1% of its velocity per second, losing 99%. A value of 0.1 means the Body keeps 10% of its velocity per second, losing 90%. A value of 1 means the Body loses no velocity. You can use very small values (e.g., 0.001) to stop the Body quickly.

The x and y components are applied separately.

Drag is applied only when acceleration is zero.

Type:
Since: 3.0.0
Focus
Focus
embedded: boolean
Focus
Focus

Description:

Whether this Body is overlapped with another and both are not moving, on at least one axis.

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
enable: boolean
Focus
Focus

Description:

Whether this Body is updated by the physics simulation.

Type:
boolean
Default: true
Since: 3.0.0
Focus
Focus
facing: number
Focus
Focus

Description:

The direction of the Body's velocity, as calculated during the last step. This is a numeric constant value (FACING_UP, FACING_DOWN, FACING_LEFT, FACING_RIGHT). If the Body is moving on both axes, this describes motion on the vertical axis only.

Type:
number
Since: 3.0.0
Focus
Focus

Description:

If this Body is immovable and in motion, friction is the proportion of this Body's motion received by the riding Body on each axis, relative to 1. The horizontal component (x) is applied only when two colliding Bodies are separated vertically. The vertical component (y) is applied only when two colliding Bodies are separated horizontally. The default value (1, 0) moves the riding Body horizontally in equal proportion to this Body and vertically not at all.

Type:
Since: 3.0.0
Focus
Focus

Description:

The Game Object this Body belongs to.

Type:
Since: 3.0.0
Focus
Focus

Description:

Acceleration due to gravity (specific to this Body), in pixels per second squared. Total gravity is the sum of this vector and the simulation's gravity.

Type:
Since: 3.0.0
Focus
Focus
halfHeight: number
Focus
Focus

Description:

Half the Body's height, in pixels.

Type:
number
Since: 3.0.0
Focus
Focus
halfWidth: number
Focus
Focus

Description:

Half the Body's width, in pixels.

Type:
number
Since: 3.0.0
Focus
Focus
<readonly> height: number
Focus
Focus

Description:

The height of the Body, in pixels. If the Body is circular, this is also the diameter. If you wish to change the height use the Body.setSize method.

Type:
number
Default: 64
Since: 3.0.0
Focus
Focus
immovable: boolean
Focus
Focus

Description:

Whether this Body can be moved by collisions with another Body.

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
isCircle: boolean
Focus
Focus

Description:

Whether this Body is circular (true) or rectangular (false).

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
<readonly> left: number
Focus
Focus

Description:

The left edge of the Body. Identical to x.

Type:
number
Since: 3.0.0
Focus
Focus
mass: number
Focus
Focus

Description:

The Body's inertia, relative to a default unit (1). With bounce, this affects the exchange of momentum (velocities) during collisions.

Type:
number
Default: 1
Since: 3.0.0
Focus
Focus
maxAngular: number
Focus
Focus

Description:

The Body's maximum angular velocity, in degrees per second.

Type:
number
Default: 1000
Since: 3.0.0
Focus
Focus
maxSpeed: number
Focus
Focus

Description:

The maximum speed this Body is allowed to reach, in pixels per second.

If not negative it limits the scalar value of speed.

Any negative value means no maximum is being applied (the default).

Type:
number
Default: -1
Since: 3.16.0
Focus
Focus
maxVelocity: Phaser.Math.Vector2
Focus
Focus

Description:

The Body's absolute maximum velocity, in pixels per second. The horizontal and vertical components are applied separately.

Type:
Since: 3.0.0
Focus
Focus
moves: boolean
Focus
Focus

Description:

Whether the Body's position and rotation are affected by its velocity, acceleration, drag, and gravity.

Type:
boolean
Default: true
Since: 3.0.0
Focus
Focus
<readonly> newVelocity: Phaser.Math.Vector2
Focus
Focus

Description:

The Body's change in position (due to velocity) at the last step, in pixels.

The size of this value depends on the simulation's step rate.

Type:
Since: 3.0.0
Focus
Focus

Description:

The offset of this Body's position from its Game Object's position, in source pixels.

Type:
Since: 3.0.0
Focus
Focus
onCollide: boolean
Focus
Focus

Description:

Whether the simulation emits a collide event when this Body collides with another.

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
onOverlap: boolean
Focus
Focus

Description:

Whether the simulation emits an overlap event when this Body overlaps with another.

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
onWorldBounds: boolean
Focus
Focus

Description:

Whether the simulation emits a worldbounds event when this Body collides with the world boundary (and collideWorldBounds is also true).

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
overlapR: number
Focus
Focus

Description:

The amount of overlap (before separation), if this Body is circular and colliding with another circular body.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
overlapX: number
Focus
Focus

Description:

The amount of horizontal overlap (before separation), if this Body is colliding with another.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
overlapY: number
Focus
Focus

Description:

The amount of vertical overlap (before separation), if this Body is colliding with another.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
<readonly> physicsType: number
Focus
Focus

Description:

The Body's physics type (dynamic or static).

Type:
number
Default: Phaser.Physics.Arcade.DYNAMIC_BODY
Since: 3.0.0
Focus
Focus

Description:

The position of this Body within the simulation.

Type:
Since: 3.0.0
Focus
Focus
preRotation: number
Focus
Focus

Description:

The Body rotation, in degrees, during the previous step.

Type:
number
Since: 3.0.0
Focus
Focus
prevFrame: Phaser.Math.Vector2
Focus
Focus

Description:

The position of this Body during the previous frame.

Type:
Since: 3.20.0
Focus
Focus
pushable: boolean
Focus
Focus

Description:

Sets if this Body can be pushed by another Body.

A body that cannot be pushed will reflect back all of the velocity it is given to the colliding body. If that body is also not pushable, then the separation will be split between them evenly.

If you want your body to never move or seperate at all, see the setImmovable method.

By default, Dynamic Bodies are always pushable.

Type:
boolean
Default: true
Since: 3.50.0
Focus
Focus
radius: number
Focus
Focus

Description:

If this Body is circular, this is the unscaled radius of the Body, as set by setCircle(), in source pixels. The true radius is equal to halfWidth.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
rotation: number
Focus
Focus

Description:

This body's rotation, in degrees, based on its angular acceleration and angular velocity. The Body's rotation controls the angle of its Game Object. It doesn't rotate the Body's own geometry, which is always an axis-aligned rectangle or a circle.

Type:
number
Since: 3.0.0
Focus
Focus
sourceHeight: number
Focus
Focus

Description:

The unscaled height of the Body, in source pixels, as set by setSize(). The default is the height of the Body's Game Object's texture frame.

Type:
number
Since: 3.0.0
Focus
Focus
sourceWidth: number
Focus
Focus

Description:

The unscaled width of the Body, in source pixels, as set by setSize(). The default is the width of the Body's Game Object's texture frame.

Type:
number
Since: 3.0.0
Focus
Focus
speed: number
Focus
Focus

Description:

The calculated magnitude of the Body's velocity, in pixels per second, during the last step.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus
syncBounds: boolean
Focus
Focus

Description:

Whether to automatically synchronize this Body's dimensions to the dimensions of its Game Object's visual bounds.

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
<readonly> top: number
Focus
Focus

Description:

The top edge of the Body. Identical to y.

Type:
number
Since: 3.0.0
Focus
Focus

Description:

Whether this Body is colliding with a Body or Static Body and in which direction. In a collision where both bodies have zero velocity, embedded will be set instead.

Type:
Since: 3.0.0
Focus
Focus
transform: object
Focus
Focus

Description:

Transformations applied to this Body.

Type:
object
Since: 3.4.0
Focus
Focus
useDamping: boolean
Focus
Focus

Description:

If this Body is using drag for deceleration this property controls how the drag is applied. If set to true drag will use a damping effect rather than a linear approach. If you are creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in the game Asteroids) then you will get a far smoother and more visually correct deceleration by using damping, avoiding the axis-drift that is prone with linear deceleration.

If you enable this property then you should use far smaller drag values than with linear, as they are used as a multiplier on the velocity. Values such as 0.05 will give a nice slow deceleration.

Type:
boolean
Default: false
Since: 3.10.0
Focus
Focus

Description:

The Body's velocity, in pixels per second.

Type:
Since: 3.0.0
Focus
Focus

Description:

This Body's touching value during the previous step.

Type:
Since: 3.0.0
Focus
Focus
<readonly> width: number
Focus
Focus

Description:

The width of the Body, in pixels. If the Body is circular, this is also the diameter. If you wish to change the width use the Body.setSize method.

Type:
number
Default: 64
Since: 3.0.0
Focus
Focus

Description:

The Arcade Physics simulation this Body belongs to.

Type:
Since: 3.0.0
Focus
Focus
<nullable> worldBounce: Phaser.Math.Vector2
Focus
Focus

Description:

Rebound following a collision with the world boundary, relative to 1. If null, bounce is used instead.

Type:
Default: null
Since: 3.0.0
Focus
Focus
x: number
Focus
Focus

Description:

The Bodys horizontal position (left edge).

Type:
number
Since: 3.0.0
Focus
Focus
y: number
Focus
Focus

Description:

The Bodys vertical position (top edge).

Type:
number
Since: 3.0.0
Focus
Focus

Methods

checkWorldBounds()
Focus
Focus

Description:

Checks for collisions between this Body and the world boundary and separates them.

Returns:
Description:

True if this Body is colliding with the world boundary.

Type:
  • boolean
Examples:
Since: 3.0.0
Focus
Focus
deltaAbsX()
Focus
Focus

Description:

The absolute (non-negative) change in this Body's horizontal position from the previous step.

Returns:
Description:

The delta value.

Type:
  • number
Examples:
Since: 3.0.0
Focus
Focus
deltaAbsY()
Focus
Focus

Description:

The absolute (non-negative) change in this Body's vertical position from the previous step.

Returns:
Description:

The delta value.

Type:
  • number
Examples:
Since: 3.0.0
Focus
Focus
deltaX()
Focus
Focus

Description:

The change in this Body's horizontal position from the previous step. This value is set during the Body's update phase.

As a Body can update multiple times per step this may not hold the final delta value for the Body. In this case, please see the deltaXFinal method.

Returns:
Description:

The delta value.

Type:
  • number
Examples:
Since: 3.0.0
Focus
Focus
deltaXFinal()
Focus
Focus

Description:

The change in this Body's horizontal position from the previous game update.

This value is set during the postUpdate phase and takes into account the deltaMax and final position of the Body.

Because this value is not calculated until postUpdate, you must listen for it during a Scene POST_UPDATE or RENDER event, and not in update, as it will not be calculated by that point. If you do use these values in update they will represent the delta from the previous game frame.

Returns:
Description:

The final delta x value.

Type:
  • number
Examples:
Since: 3.22.0
Focus
Focus
deltaY()
Focus
Focus

Description:

The change in this Body's vertical position from the previous step. This value is set during the Body's update phase.

As a Body can update multiple times per step this may not hold the final delta value for the Body. In this case, please see the deltaYFinal method.

Returns:
Description:

The delta value.

Type:
  • number
Examples:
Since: 3.0.0
Focus
Focus
deltaYFinal()
Focus
Focus

Description:

The change in this Body's vertical position from the previous game update.

This value is set during the postUpdate phase and takes into account the deltaMax and final position of the Body.

Because this value is not calculated until postUpdate, you must listen for it during a Scene POST_UPDATE or RENDER event, and not in update, as it will not be calculated by that point. If you do use these values in update they will represent the delta from the previous game frame.

Returns:
Description:

The final delta y value.

Type:
  • number
Examples:
Since: 3.22.0
Focus
Focus
deltaZ()
Focus
Focus

Description:

The change in this Body's rotation from the previous step, in degrees.

Returns:
Description:

The delta value.

Type:
  • number
Examples:
Since: 3.0.0
Focus
Focus
destroy()
Focus
Focus

Description:

Disables this Body and marks it for deletion by the simulation.

Examples:
Since: 3.0.0
Focus
Focus
drawDebug(graphic)
Focus
Focus

Description:

Draws this Body and its velocity, if enabled.

Parameters:

name type description
graphic Phaser.GameObjects.Graphics

The Graphics object to draw on.

Examples:
Since: 3.0.0
Focus
Focus
getBounds(obj)
Focus
Focus

Description:

Copies the coordinates of this Body's edges into an object.

Parameters:

name type description
obj Phaser.Types.Physics.Arcade.ArcadeBodyBounds

An object to copy the values into.

Returns:
Description:
  • An object with {x, y, right, bottom}.
Examples:
Since: 3.0.0
Focus
Focus
hitTest(x, y)
Focus
Focus

Description:

Tests if the coordinates are within this Body.

Parameters:

name type description
x number

The horizontal coordinate.

y number

The vertical coordinate.

Returns:
Description:

True if (x, y) is within this Body.

Type:
  • boolean
Examples:
Since: 3.0.0
Focus
Focus
onCeiling()
Focus
Focus

Description:

Whether this Body is touching a tile or the world boundary while moving up.

Returns:
Description:

True if touching.

Type:
  • boolean
Examples:
Since: 3.0.0
Focus
Focus
onFloor()
Focus
Focus

Description:

Whether this Body is touching a tile or the world boundary while moving down.

Returns:
Description:

True if touching.

Type:
  • boolean
Examples:
Since: 3.0.0
Focus
Focus
onWall()
Focus
Focus

Description:

Whether this Body is touching a tile or the world boundary while moving left or right.

Returns:
Description:

True if touching.

Type:
  • boolean
Examples:
Since: 3.0.0
Focus
Focus
postUpdate()
Focus
Focus

Description:

Feeds the Body results back into the parent Game Object.

This method is called every game frame, regardless if the world steps or not.

Examples:
Since: 3.0.0
Focus
Focus
preUpdate(willStep, delta)
Focus
Focus

Description:

Syncs the position body position with the parent Game Object.

This method is called every game frame, regardless if the world steps or not.

Parameters:

name type description
willStep boolean

Will this Body run an update as well?

delta number

The delta time, in seconds, elapsed since the last frame.

Examples:
Since: 3.17.0
Focus
Focus
processX(x, [vx], [left], [right])
Focus
Focus

Description:

This is an internal handler, called by the ProcessX function as part of the collision step. You should almost never call this directly.

Parameters:

name type arguments description
x number

The amount to add to the Body position.

vx number <optional>

The amount to add to the Body velocity.

left boolean <optional>

Set the blocked.left value?

right boolean <optional>

Set the blocked.right value?

Examples:
Since: 3.50.0
Focus
Focus
processY(y, [vy], [up], [down])
Focus
Focus

Description:

This is an internal handler, called by the ProcessY function as part of the collision step. You should almost never call this directly.

Parameters:

name type arguments description
y number

The amount to add to the Body position.

vy number <optional>

The amount to add to the Body velocity.

up boolean <optional>

Set the blocked.up value?

down boolean <optional>

Set the blocked.down value?

Examples:
Since: 3.50.0
Focus
Focus
reset(x, y)
Focus
Focus

Description:

Sets this Body's parent Game Object to the given coordinates and resets this Body at the new coordinates. If the Body had any velocity or acceleration it is lost as a result of calling this.

Parameters:

name type description
x number

The horizontal position to place the Game Object.

y number

The vertical position to place the Game Object.

Examples:
Since: 3.0.0
Focus
Focus
resetFlags([clear])
Focus
Focus

Description:

Prepares the Body for a physics step by resetting the wasTouching, touching and blocked states.

This method is only called if the physics world is going to run a step this frame.

Parameters:

name type arguments Default description
clear boolean <optional> false

Set the wasTouching values to their defaults.

Examples:
Since: 3.18.0
Focus
Focus
setAcceleration(x, y)
Focus
Focus

Description:

Sets the Body's acceleration.

Parameters:

name type description
x number

The horizontal component, in pixels per second squared.

y number

The vertical component, in pixels per second squared.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setAccelerationX(value)
Focus
Focus

Description:

Sets the Body's horizontal acceleration.

Parameters:

name type description
value number

The acceleration, in pixels per second squared.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setAccelerationY(value)
Focus
Focus

Description:

Sets the Body's vertical acceleration.

Parameters:

name type description
value number

The acceleration, in pixels per second squared.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setAllowDrag([value])
Focus
Focus

Description:

Enables or disables drag.

Parameters:

name type arguments Default description
value boolean <optional> true

true to allow drag on this body, or false to disable it.

Returns:
Description:

This Body object.

Examples:
Since: 3.9.0
Focus
Focus
setAllowGravity([value])
Focus
Focus

Description:

Enables or disables gravity's effect on this Body.

Parameters:

name type arguments Default description
value boolean <optional> true

true to allow gravity on this body, or false to disable it.

Returns:
Description:

This Body object.

Examples:
Since: 3.9.0
Focus
Focus
setAllowRotation([value])
Focus
Focus

Description:

Enables or disables rotation.

Parameters:

name type arguments Default description
value boolean <optional> true

true to allow rotation on this body, or false to disable it.

Returns:
Description:

This Body object.

Examples:
Since: 3.9.0
Focus
Focus
setAngularAcceleration(value)
Focus
Focus

Description:

Sets the Body's angular acceleration.

Parameters:

name type description
value number

The acceleration, in degrees per second squared.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setAngularDrag(value)
Focus
Focus

Description:

Sets the Body's angular drag.

Parameters:

name type description
value number

The drag, in degrees per second squared.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setAngularVelocity(value)
Focus
Focus

Description:

Sets the Body's angular velocity.

Parameters:

name type description
value number

The velocity, in degrees per second.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setBounce(x, y)
Focus
Focus

Description:

Sets the Body's bounce.

Parameters:

name type description
x number

The horizontal bounce, relative to 1.

y number

The vertical bounce, relative to 1.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setBounceX(value)
Focus
Focus

Description:

Sets the Body's horizontal bounce.

Parameters:

name type description
value number

The bounce, relative to 1.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setBounceY(value)
Focus
Focus

Description:

Sets the Body's vertical bounce.

Parameters:

name type description
value number

The bounce, relative to 1.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setBoundsRectangle([bounds])
Focus
Focus

Description:

Sets a custom collision boundary rectangle. Use if you want to have a custom boundary instead of the world boundaries.

Parameters:

name type arguments description
bounds Phaser.Geom.Rectangle <optional>

The new boundary rectangle. Pass null to use the World bounds.

Returns:
Description:

This Body object.

Examples:
Since: 3.20
Focus
Focus
setCircle(radius, [offsetX], [offsetY])
Focus
Focus

Description:

Sizes and positions this Body, as a circle.

Parameters:

name type arguments description
radius number

The radius of the Body, in source pixels.

offsetX number <optional>

The horizontal offset of the Body from its Game Object, in source pixels.

offsetY number <optional>

The vertical offset of the Body from its Game Object, in source pixels.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setCollideWorldBounds([value], [bounceX], [bounceY], [onWorldBounds])
Focus
Focus

Description:

Sets whether this Body collides with the world boundary.

Optionally also sets the World Bounce and onWorldBounds values.

Parameters:

name type arguments Default description
value boolean <optional> true

true if the Body should collide with the world bounds, otherwise false.

bounceX number <optional>

If given this replaces the Body's worldBounce.x value.

bounceY number <optional>

If given this replaces the Body's worldBounce.y value.

onWorldBounds boolean <optional>

If given this replaces the Body's onWorldBounds value.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setDamping(value)
Focus
Focus

Description:

If this Body is using drag for deceleration this property controls how the drag is applied. If set to true drag will use a damping effect rather than a linear approach. If you are creating a game where the Body moves freely at any angle (i.e. like the way the ship moves in the game Asteroids) then you will get a far smoother and more visually correct deceleration by using damping, avoiding the axis-drift that is prone with linear deceleration.

If you enable this property then you should use far smaller drag values than with linear, as they are used as a multiplier on the velocity. Values such as 0.95 will give a nice slow deceleration, where-as smaller values, such as 0.5 will stop an object almost immediately.

Parameters:

name type description
value boolean

true to use damping, or false to use drag.

Returns:
Description:

This Body object.

Examples:
Since: 3.50.0
Focus
Focus
setDrag(x, y)
Focus
Focus

Description:

Sets the Body's drag.

Parameters:

name type description
x number

The horizontal component, in pixels per second squared.

y number

The vertical component, in pixels per second squared.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setDragX(value)
Focus
Focus

Description:

Sets the Body's horizontal drag.

Parameters:

name type description
value number

The drag, in pixels per second squared.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setDragY(value)
Focus
Focus

Description:

Sets the Body's vertical drag.

Parameters:

name type description
value number

The drag, in pixels per second squared.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setEnable([value])
Focus
Focus

Description:

Sets the Body's enable property.

Parameters:

name type arguments Default description
value boolean <optional> true

The value to assign to enable.

Returns:
Description:

This Body object.

Examples:
Since: 3.15.0
Focus
Focus
setFriction(x, y)
Focus
Focus

Description:

Sets the Body's friction.

Parameters:

name type description
x number

The horizontal component, relative to 1.

y number

The vertical component, relative to 1.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setFrictionX(value)
Focus
Focus

Description:

Sets the Body's horizontal friction.

Parameters:

name type description
value number

The friction value, relative to 1.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setFrictionY(value)
Focus
Focus

Description:

Sets the Body's vertical friction.

Parameters:

name type description
value number

The friction value, relative to 1.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setGravity(x, y)
Focus
Focus

Description:

Sets the Body's gravity.

Parameters:

name type description
x number

The horizontal component, in pixels per second squared.

y number

The vertical component, in pixels per second squared.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setGravityX(value)
Focus
Focus

Description:

Sets the Body's horizontal gravity.

Parameters:

name type description
value number

The gravity, in pixels per second squared.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setGravityY(value)
Focus
Focus

Description:

Sets the Body's vertical gravity.

Parameters:

name type description
value number

The gravity, in pixels per second squared.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setImmovable([value])
Focus
Focus

Description:

Sets the Body's immovable property.

Parameters:

name type arguments Default description
value boolean <optional> true

The value to assign to immovable.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setMass(value)
Focus
Focus

Description:

Sets the Body's mass.

Parameters:

name type description
value number

The mass value, relative to 1.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setMaxSpeed(value)
Focus
Focus

Description:

Sets the maximum speed the Body can move.

Parameters:

name type description
value number

The maximum speed value, in pixels per second. Set to a negative value to disable.

Returns:
Description:

This Body object.

Examples:
Since: 3.16.0
Focus
Focus
setMaxVelocity(x, [y])
Focus
Focus

Description:

Sets the Body's maximum velocity.

Parameters:

name type arguments Default description
x number

The horizontal velocity, in pixels per second.

y number <optional> x

The vertical velocity, in pixels per second.

Returns:
Description:

This Body object.

Examples:
Since: 3.10.0
Focus
Focus
setMaxVelocityX(value)
Focus
Focus

Description:

Sets the Body's maximum horizontal velocity.

Parameters:

name type description
value number

The maximum horizontal velocity, in pixels per second.

Returns:
Description:

This Body object.

Examples:
Since: 3.50.0
Focus
Focus
setMaxVelocityY(value)
Focus
Focus

Description:

Sets the Body's maximum vertical velocity.

Parameters:

name type description
value number

The maximum vertical velocity, in pixels per second.

Returns:
Description:

This Body object.

Examples:
Since: 3.50.0
Focus
Focus
setOffset(x, [y])
Focus
Focus

Description:

Sets the offset of the Body's position from its Game Object's position. The Body's position isn't changed until the next preUpdate.

Parameters:

name type arguments Default description
x number

The horizontal offset, in source pixels.

y number <optional> x

The vertical offset, in source pixels.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setSize([width], [height], [center])
Focus
Focus

Description:

Sizes and positions this Body, as a rectangle. Modifies the Body offset if center is true (the default). Resets the width and height to match current frame, if no width and height provided and a frame is found.

Parameters:

name type arguments Default description
width number <optional>

The width of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame width.

height number <optional>

The height of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame height.

center boolean <optional> true

Modify the Body's offset, placing the Body's center on its Game Object's center. Only works if the Game Object has the getCenter method.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setVelocity(x, [y])
Focus
Focus

Description:

Sets the Body's velocity.

Parameters:

name type arguments Default description
x number

The horizontal velocity, in pixels per second.

y number <optional> x

The vertical velocity, in pixels per second.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setVelocityX(value)
Focus
Focus

Description:

Sets the Body's horizontal velocity.

Parameters:

name type description
value number

The velocity, in pixels per second.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
setVelocityY(value)
Focus
Focus

Description:

Sets the Body's vertical velocity.

Parameters:

name type description
value number

The velocity, in pixels per second.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
stop()
Focus
Focus

Description:

Sets acceleration, velocity, and speed to zero.

Returns:
Description:

This Body object.

Examples:
Since: 3.0.0
Focus
Focus
update(delta)
Focus
Focus

Description:

Performs a single physics step and updates the body velocity, angle, speed and other properties.

This method can be called multiple times per game frame, depending on the physics step rate.

The results are synced back to the Game Object in postUpdate.

Parameters:

name type description
delta number

The delta time, in seconds, elapsed since the last frame.

Examples:
Since: 3.0.0
Focus
Focus
updateBounds()
Focus
Focus

Description:

Updates the Body's transform, width, height, and center from its Game Object. The Body's position isn't changed.

Examples:
Since: 3.0.0
Focus
Focus
updateCenter()
Focus
Focus

Description:

Updates the Body's center from its position, width, and height.

Examples:
Since: 3.0.0
Focus
Focus
updateFromGameObject()
Focus
Focus

Description:

Updates the Body's position, width, height, and center from its Game Object and offset.

You don't need to call this for Dynamic Bodies, as it happens automatically during the physics step. But you could use it if you have modified the Body offset or Game Object transform and need to immediately read the Body's new position or center.

To resynchronize the Body with its Game Object, use reset() instead.

Examples:
Since: 3.24.0
Focus
Focus
willDrawDebug()
Focus
Focus

Description:

Whether this Body will be drawn to the debug display.

Returns:
Description:

True if either debugShowBody or debugShowVelocity are enabled.

Type:
  • boolean
Examples:
Since: 3.0.0
Focus
Focus