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
- Source: src/physics/arcade/Body.js (Line 16)
Members
-
acceleration :Phaser.Math.Vector2
-
The Body's change in velocity, in pixels per second squared.
Type:
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 316)
-
allowDrag :boolean
-
Whether this Body's velocity is affected by its
drag
.Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- true
- Source: src/physics/arcade/Body.js (Line 325)
-
allowGravity :boolean
-
Whether this Body's position is affected by gravity (local or world).
Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- true
- Source: src/physics/arcade/Body.js (Line 354)
- See:
-
allowRotation :boolean
-
Whether this Body's
rotation
is affected by its angular acceleration and angular velocity.Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- true
- Source: src/physics/arcade/Body.js (Line 174)
-
angle :number
-
The calculated angle of this Body's velocity vector, in radians, during the last step.
Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/physics/arcade/Body.js (Line 553)
-
angularAcceleration :number
-
The Body's angular acceleration (change in angular velocity), in degrees per second squared.
Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/physics/arcade/Body.js (Line 510)
-
angularDrag :number
-
Loss of angular velocity due to angular movement, in degrees per second.
Angular drag is applied only when angular acceleration is zero.
Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/physics/arcade/Body.js (Line 520)
-
angularVelocity :number
-
The rate of change of this Body's
rotation
, in degrees per second.Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/physics/arcade/Body.js (Line 500)
-
blocked :Phaser.Types.Physics.Arcade.ArcadeBodyCollision
-
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
- Source: src/physics/arcade/Body.js (Line 734)
- See:
-
<readonly> bottom :number
-
The bottom edge of this Body.
Type:
- number
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2510)
-
bounce :Phaser.Math.Vector2
-
Rebound following a collision, relative to 1.
Type:
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 377)
-
center :Phaser.Math.Vector2
-
The center of the Body. The midpoint of its
position
(top-left corner) and its bottom-right corner.Type:
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 276)
-
checkCollision :Phaser.Types.Physics.Arcade.ArcadeBodyCollision
-
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
- Source: src/physics/arcade/Body.js (Line 700)
-
collideWorldBounds :boolean
-
Whether this Body interacts with the world boundary.
Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/physics/arcade/Body.js (Line 690)
-
customBoundsRectangle :Phaser.Geom.Rectangle
-
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
- Source: src/physics/arcade/Body.js (Line 397)
-
customSeparateX :boolean
-
A flag disabling the default horizontal separation of colliding bodies. Pass your own
collideCallback
to the collider.Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/physics/arcade/Body.js (Line 628)
-
customSeparateY :boolean
-
A flag disabling the default vertical separation of colliding bodies. Pass your own
collideCallback
to the collider.Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/physics/arcade/Body.js (Line 639)
-
debugBodyColor :number
-
The color of this Body on the debug display.
Type:
- number
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 92)
-
debugShowBody :boolean
-
Whether the Body is drawn to the debug display.
Type:
- boolean
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 74)
-
debugShowVelocity :boolean
-
Whether the Body's velocity is drawn to the debug display.
Type:
- boolean
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 83)
-
deltaMax :Phaser.Math.Vector2
-
The Body's absolute maximum change in position, in pixels per step.
Type:
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 307)
-
drag :Phaser.Math.Vector2
-
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 loses 99% of its velocity per second. A value of 0.1 means the Body loses 90% of its velocity per second. A value of 1 means the Body loses no velocity.The x and y components are applied separately.
Drag is applied only when
acceleration
is zero.Type:
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 335)
-
embedded :boolean
-
Whether this Body is overlapped with another and both are not moving, on at least one axis.
Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/physics/arcade/Body.js (Line 680)
-
enable :boolean
-
Whether this Body is updated by the physics simulation.
Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- true
- Source: src/physics/arcade/Body.js (Line 101)
-
facing :number
-
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
-
friction :Phaser.Math.Vector2
-
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
- Source: src/physics/arcade/Body.js (Line 470)
-
gameObject :Phaser.GameObjects.GameObject
-
The Game Object this Body belongs to.
Type:
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 48)
-
gravity :Phaser.Math.Vector2
-
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
- Source: src/physics/arcade/Body.js (Line 366)
- See:
-
halfHeight :number
-
Half the Body's height, in pixels.
Type:
- number
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 267)
-
halfWidth :number
-
Half the Body's width, in pixels.
Type:
- number
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 258)
-
<readonly> height :number
-
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
- Since: 3.0.0
- Default Value:
-
- 64
- Source: src/physics/arcade/Body.js (Line 217)
-
immovable :boolean
-
Whether this Body can be moved by collisions with another Body.
Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/physics/arcade/Body.js (Line 589)
-
isCircle :boolean
-
Whether this Body is circular (true) or rectangular (false).
Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/physics/arcade/Body.js (Line 111)
- See:
-
<readonly> left :number
-
The left edge of the Body. Identical to x.
Type:
- number
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2459)
-
mass :number
-
The Body's inertia, relative to a default unit (1). With
bounce
, this affects the exchange of momentum (velocities) during collisions.Type:
- number
- Since: 3.0.0
- Default Value:
-
- 1
- Source: src/physics/arcade/Body.js (Line 542)
-
maxAngular :number
-
The Body's maximum angular velocity, in degrees per second.
Type:
- number
- Since: 3.0.0
- Default Value:
-
- 1000
- Source: src/physics/arcade/Body.js (Line 532)
-
maxSpeed :number
-
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
- Since: 3.16.0
- Default Value:
-
- -1
- Source: src/physics/arcade/Body.js (Line 456)
-
maxVelocity :Phaser.Math.Vector2
-
The Body's absolute maximum velocity, in pixels per second. The horizontal and vertical components are applied separately.
Type:
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 446)
-
moves :boolean
-
Whether the Body's position and rotation are affected by its velocity, acceleration, drag, and gravity.
Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- true
- Source: src/physics/arcade/Body.js (Line 618)
-
<readonly> newVelocity :Phaser.Math.Vector2
-
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
- Source: src/physics/arcade/Body.js (Line 295)
-
offset :Phaser.Math.Vector2
-
The offset of this Body's position from its Game Object's position, in source pixels.
Type:
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 134)
- See:
-
onCollide :boolean
-
Whether the simulation emits a
collide
event when this Body collides with another.Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/physics/arcade/Body.js (Line 424)
- See:
-
- Phaser.Physics.Arcade.World#COLLIDE
-
onOverlap :boolean
-
Whether the simulation emits an
overlap
event when this Body overlaps with another.Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/physics/arcade/Body.js (Line 435)
- See:
-
- Phaser.Physics.Arcade.World#OVERLAP
-
onWorldBounds :boolean
-
Whether the simulation emits a
worldbounds
event when this Body collides with the world boundary (andcollideWorldBounds
is also true).Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/physics/arcade/Body.js (Line 413)
- See:
-
- Phaser.Physics.Arcade.World#WORLD_BOUNDS
-
overlapR :number
-
The amount of overlap (before separation), if this Body is circular and colliding with another circular body.
Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/physics/arcade/Body.js (Line 670)
-
overlapX :number
-
The amount of horizontal overlap (before separation), if this Body is colliding with another.
Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/physics/arcade/Body.js (Line 650)
-
overlapY :number
-
The amount of vertical overlap (before separation), if this Body is colliding with another.
Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/physics/arcade/Body.js (Line 660)
-
<readonly> physicsType :number
-
The Body's physics type (dynamic or static).
Type:
- number
- Since: 3.0.0
- Default Value:
-
- Phaser.Physics.Arcade.DYNAMIC_BODY
- Source: src/physics/arcade/Body.js (Line 758)
-
position :Phaser.Math.Vector2
-
The position of this Body within the simulation.
Type:
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 144)
-
preRotation :number
-
The Body rotation, in degrees, during the previous step.
Type:
- number
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 195)
-
prev :Phaser.Math.Vector2
-
The position of this Body during the previous step.
Type:
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 156)
-
prevFrame :Phaser.Math.Vector2
-
The position of this Body during the previous frame.
Type:
- Since: 3.20.0
- Source: src/physics/arcade/Body.js (Line 165)
-
pushable :boolean
-
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
- Since: 3.50.0
- Default Value:
-
- true
- Source: src/physics/arcade/Body.js (Line 599)
- See:
-
- Phaser.GameObjects.Components.Pushable#setPushable
-
radius :number
-
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
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/physics/arcade/Body.js (Line 122)
- See:
-
<readonly> right :number
-
The right edge of the Body.
Type:
- number
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2476)
-
rotation :number
-
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
- Source: src/physics/arcade/Body.js (Line 184)
-
sourceHeight :number
-
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
- Source: src/physics/arcade/Body.js (Line 241)
- See:
-
sourceWidth :number
-
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
- Source: src/physics/arcade/Body.js (Line 230)
- See:
-
speed :number
-
The calculated magnitude of the Body's velocity, in pixels per second, during the last step.
Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/physics/arcade/Body.js (Line 563)
-
syncBounds :boolean
-
Whether to automatically synchronize this Body's dimensions to the dimensions of its Game Object's visual bounds.
Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/physics/arcade/Body.js (Line 747)
- See:
-
<readonly> top :number
-
The top edge of the Body. Identical to y.
Type:
- number
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2493)
-
touching :Phaser.Types.Physics.Arcade.ArcadeBodyCollision
-
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
- Source: src/physics/arcade/Body.js (Line 710)
- See:
-
transform :object
-
Transformations applied to this Body.
Type:
- object
- Since: 3.4.0
- Source: src/physics/arcade/Body.js (Line 57)
-
useDamping :boolean
-
If this Body is using
drag
for deceleration this property controls how the drag is applied. If set totrue
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
- Since: 3.10.0
- Default Value:
-
- false
- Source: src/physics/arcade/Body.js (Line 482)
-
velocity :Phaser.Math.Vector2
-
The Body's velocity, in pixels per second.
Type:
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 286)
-
wasTouching :Phaser.Types.Physics.Arcade.ArcadeBodyCollision
-
This Body's
touching
value during the previous step.Type:
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 723)
- See:
-
<readonly> width :number
-
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
- Since: 3.0.0
- Default Value:
-
- 64
- Source: src/physics/arcade/Body.js (Line 204)
-
world :Phaser.Physics.Arcade.World
-
The Arcade Physics simulation this Body belongs to.
Type:
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 39)
-
<nullable> worldBounce :Phaser.Math.Vector2
-
Rebound following a collision with the world boundary, relative to 1. If null,
bounce
is used instead.Type:
- Since: 3.0.0
- Default Value:
-
- null
- Source: src/physics/arcade/Body.js (Line 386)
-
x :number
-
The Bodys horizontal position (left edge).
Type:
- number
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2417)
-
y :number
-
The Bodys vertical position (top edge).
Type:
- number
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2438)
Methods
-
checkWorldBounds()
-
Checks for collisions between this Body and the world boundary and separates them.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1183)
Returns:
True if this Body is colliding with the world boundary.
- Type
- boolean
-
deltaAbsX()
-
The absolute (non-negative) change in this Body's horizontal position from the previous step.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1509)
Returns:
The delta value.
- Type
- number
-
deltaAbsY()
-
The absolute (non-negative) change in this Body's vertical position from the previous step.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1522)
Returns:
The delta value.
- Type
- number
-
deltaX()
-
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.- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1535)
Returns:
The delta value.
- Type
- number
-
deltaXFinal()
-
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 thedeltaMax
and final position of the Body.Because this value is not calculated until
postUpdate
, you must listen for it during a ScenePOST_UPDATE
orRENDER
event, and not inupdate
, as it will not be calculated by that point. If you do use these values inupdate
they will represent the delta from the previous game frame.- Since: 3.22.0
- Source: src/physics/arcade/Body.js (Line 1569)
Returns:
The final delta x value.
- Type
- number
-
deltaY()
-
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.- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1552)
Returns:
The delta value.
- Type
- number
-
deltaYFinal()
-
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 thedeltaMax
and final position of the Body.Because this value is not calculated until
postUpdate
, you must listen for it during a ScenePOST_UPDATE
orRENDER
event, and not inupdate
, as it will not be calculated by that point. If you do use these values inupdate
they will represent the delta from the previous game frame.- Since: 3.22.0
- Source: src/physics/arcade/Body.js (Line 1590)
Returns:
The final delta y value.
- Type
- number
-
deltaZ()
-
The change in this Body's rotation from the previous step, in degrees.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1611)
Returns:
The delta value.
- Type
- number
-
destroy()
-
Disables this Body and marks it for deletion by the simulation.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1624)
-
drawDebug(graphic)
-
Draws this Body and its velocity, if enabled.
Parameters:
Name Type Description graphic
Phaser.GameObjects.Graphics The Graphics object to draw on.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1640)
-
getBounds(obj)
-
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.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1417)
Returns:
- An object with {x, y, right, bottom}.
-
hitTest(x, y)
-
Tests if the coordinates are within this Body.
Parameters:
Name Type Description x
number The horizontal coordinate.
y
number The vertical coordinate.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1437)
Returns:
True if (x, y) is within this Body.
- Type
- boolean
-
onCeiling()
-
Whether this Body is touching a tile or the world boundary while moving up.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1481)
- See:
Returns:
True if touching.
- Type
- boolean
-
onFloor()
-
Whether this Body is touching a tile or the world boundary while moving down.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1467)
- See:
Returns:
True if touching.
- Type
- boolean
-
onWall()
-
Whether this Body is touching a tile or the world boundary while moving left or right.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1495)
- See:
Returns:
True if touching.
- Type
- boolean
-
postUpdate()
-
Feeds the Body results back into the parent Game Object.
This method is called every game frame, regardless if the world steps or not.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1092)
-
preUpdate(willStep, delta)
-
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.
- Since: 3.17.0
- Source: src/physics/arcade/Body.js (Line 1008)
-
processX(x [, vx] [, left] [, right])
-
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 Argument 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?
- Since: 3.50.0
- Source: src/physics/arcade/Body.js (Line 2345)
-
processY(y [, vy] [, up] [, down])
-
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 Argument 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?
- Since: 3.50.0
- Source: src/physics/arcade/Body.js (Line 2381)
-
reset(x, y)
-
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.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1360)
-
resetFlags( [clear])
-
Prepares the Body for a physics step by resetting the
wasTouching
,touching
andblocked
states.This method is only called if the physics world is going to run a step this frame.
Parameters:
Name Type Argument Default Description clear
boolean <optional>
false Set the
wasTouching
values to their defaults.- Since: 3.18.0
- Source: src/physics/arcade/Body.js (Line 950)
-
setAcceleration(x, y)
-
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.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1946)
Returns:
This Body object.
-
setAccelerationX(value)
-
Sets the Body's horizontal acceleration.
Parameters:
Name Type Description value
number The acceleration, in pixels per second squared.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1964)
Returns:
This Body object.
-
setAccelerationY(value)
-
Sets the Body's vertical acceleration.
Parameters:
Name Type Description value
number The acceleration, in pixels per second squared.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1981)
Returns:
This Body object.
-
setAllowDrag( [value])
-
Enables or disables drag.
Parameters:
Name Type Argument Default Description value
boolean <optional>
true true
to allow drag on this body, orfalse
to disable it.- Since: 3.9.0
- Source: src/physics/arcade/Body.js (Line 1998)
- See:
Returns:
This Body object.
-
setAllowGravity( [value])
-
Enables or disables gravity's effect on this Body.
Parameters:
Name Type Argument Default Description value
boolean <optional>
true true
to allow gravity on this body, orfalse
to disable it.- Since: 3.9.0
- Source: src/physics/arcade/Body.js (Line 2018)
- See:
Returns:
This Body object.
-
setAllowRotation( [value])
-
Enables or disables rotation.
Parameters:
Name Type Argument Default Description value
boolean <optional>
true true
to allow rotation on this body, orfalse
to disable it.- Since: 3.9.0
- Source: src/physics/arcade/Body.js (Line 2038)
- See:
Returns:
This Body object.
-
setAngularAcceleration(value)
-
Sets the Body's angular acceleration.
Parameters:
Name Type Description value
number The acceleration, in degrees per second squared.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2256)
Returns:
This Body object.
-
setAngularDrag(value)
-
Sets the Body's angular drag.
Parameters:
Name Type Description value
number The drag, in degrees per second squared.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2273)
Returns:
This Body object.
-
setAngularVelocity(value)
-
Sets the Body's angular velocity.
Parameters:
Name Type Description value
number The velocity, in degrees per second.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2239)
Returns:
This Body object.
-
setBounce(x, y)
-
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.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1894)
Returns:
This Body object.
-
setBounceX(value)
-
Sets the Body's horizontal bounce.
Parameters:
Name Type Description value
number The bounce, relative to 1.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1912)
Returns:
This Body object.
-
setBounceY(value)
-
Sets the Body's vertical bounce.
Parameters:
Name Type Description value
number The bounce, relative to 1.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1929)
Returns:
This Body object.
-
setBoundsRectangle( [bounds])
-
Sets a custom collision boundary rectangle. Use if you want to have a custom boundary instead of the world boundaries.
Parameters:
Name Type Argument Description bounds
Phaser.Geom.Rectangle <optional>
<nullable>
The new boundary rectangle. Pass
null
to use the World bounds.- Since: 3.20
- Source: src/physics/arcade/Body.js (Line 1165)
Returns:
This Body object.
-
setCircle(radius [, offsetX] [, offsetY])
-
Sizes and positions this Body, as a circle.
Parameters:
Name Type Argument 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.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1317)
Returns:
This Body object.
-
setCollideWorldBounds( [value] [, bounceX] [, bounceY] [, onWorldBounds])
-
Sets whether this Body collides with the world boundary.
Optionally also sets the World Bounce and
onWorldBounds
values.Parameters:
Name Type Argument Default Description value
boolean <optional>
true true
if the Body should collide with the world bounds, otherwisefalse
.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.- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1708)
Returns:
This Body object.
-
setDamping(value)
-
If this Body is using
drag
for deceleration this property controls how the drag is applied. If set totrue
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, orfalse
to use drag.- Since: 3.50.0
- Source: src/physics/arcade/Body.js (Line 2076)
Returns:
This Body object.
-
setDrag(x, y)
-
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.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2058)
Returns:
This Body object.
-
setDragX(value)
-
Sets the Body's horizontal drag.
Parameters:
Name Type Description value
number The drag, in pixels per second squared.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2101)
Returns:
This Body object.
-
setDragY(value)
-
Sets the Body's vertical drag.
Parameters:
Name Type Description value
number The drag, in pixels per second squared.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2118)
Returns:
This Body object.
-
setEnable( [value])
-
Sets the Body's
enable
property.Parameters:
Name Type Argument Default Description value
boolean <optional>
true The value to assign to
enable
.- Since: 3.15.0
- Source: src/physics/arcade/Body.js (Line 2326)
Returns:
This Body object.
-
setFriction(x, y)
-
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.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2187)
Returns:
This Body object.
-
setFrictionX(value)
-
Sets the Body's horizontal friction.
Parameters:
Name Type Description value
number The friction value, relative to 1.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2205)
Returns:
This Body object.
-
setFrictionY(value)
-
Sets the Body's vertical friction.
Parameters:
Name Type Description value
number The friction value, relative to 1.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2222)
Returns:
This Body object.
-
setGravity(x, y)
-
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.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2135)
Returns:
This Body object.
-
setGravityX(value)
-
Sets the Body's horizontal gravity.
Parameters:
Name Type Description value
number The gravity, in pixels per second squared.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2153)
Returns:
This Body object.
-
setGravityY(value)
-
Sets the Body's vertical gravity.
Parameters:
Name Type Description value
number The gravity, in pixels per second squared.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2170)
Returns:
This Body object.
-
setImmovable( [value])
-
Sets the Body's
immovable
property.Parameters:
Name Type Argument Default Description value
boolean <optional>
true The value to assign to
immovable
.- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2307)
Returns:
This Body object.
-
setMass(value)
-
Sets the Body's mass.
Parameters:
Name Type Description value
number The mass value, relative to 1.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 2290)
Returns:
This Body object.
-
setMaxSpeed(value)
-
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.
- Since: 3.16.0
- Source: src/physics/arcade/Body.js (Line 1877)
Returns:
This Body object.
-
setMaxVelocity(x [, y])
-
Sets the Body's maximum velocity.
Parameters:
Name Type Argument Default Description x
number The horizontal velocity, in pixels per second.
y
number <optional>
x The vertical velocity, in pixels per second.
- Since: 3.10.0
- Source: src/physics/arcade/Body.js (Line 1825)
Returns:
This Body object.
-
setMaxVelocityX(value)
-
Sets the Body's maximum horizontal velocity.
Parameters:
Name Type Description value
number The maximum horizontal velocity, in pixels per second.
- Since: 3.50.0
- Source: src/physics/arcade/Body.js (Line 1843)
Returns:
This Body object.
-
setMaxVelocityY(value)
-
Sets the Body's maximum vertical velocity.
Parameters:
Name Type Description value
number The maximum vertical velocity, in pixels per second.
- Since: 3.50.0
- Source: src/physics/arcade/Body.js (Line 1860)
Returns:
This Body object.
-
setOffset(x [, y])
-
Sets the offset of the Body's position from its Game Object's position. The Body's
position
isn't changed until the nextpreUpdate
.Parameters:
Name Type Argument Default Description x
number The horizontal offset, in source pixels.
y
number <optional>
x The vertical offset, in source pixels.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1241)
Returns:
This Body object.
-
setSize( [width] [, height] [, center])
-
Sizes and positions this Body, as a rectangle. Modifies the Body
offset
ifcenter
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 Argument 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 thegetCenter
method.- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1262)
Returns:
This Body object.
-
setVelocity(x [, y])
-
Sets the Body's velocity.
Parameters:
Name Type Argument Default Description x
number The horizontal velocity, in pixels per second.
y
number <optional>
x The vertical velocity, in pixels per second.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1758)
Returns:
This Body object.
-
setVelocityX(value)
-
Sets the Body's horizontal velocity.
Parameters:
Name Type Description value
number The velocity, in pixels per second.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1781)
Returns:
This Body object.
-
setVelocityY(value)
-
Sets the Body's vertical velocity.
Parameters:
Name Type Description value
number The velocity, in pixels per second.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1803)
Returns:
This Body object.
-
stop()
-
Sets acceleration, velocity, and speed to zero.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1398)
Returns:
This Body object.
-
update(delta)
-
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.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1045)
Fires:
-
updateBounds()
-
Updates the Body's
transform
,width
,height
, andcenter
from its Game Object. The Body'sposition
isn't changed.- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 844)
-
updateCenter()
-
Updates the Body's
center
from itsposition
,width
, andheight
.- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 915)
-
updateFromGameObject()
-
Updates the Body's
position
,width
,height
, andcenter
from its Game Object andoffset
.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
orcenter
.To resynchronize the Body with its Game Object, use
reset()
instead.- Since: 3.24.0
- Source: src/physics/arcade/Body.js (Line 926)
-
willDrawDebug()
-
Whether this Body will be drawn to the debug display.
- Since: 3.0.0
- Source: src/physics/arcade/Body.js (Line 1695)
Returns:
True if either
debugShowBody
ordebugShowVelocity
are enabled.- Type
- boolean