Body

arcade.Body (Class)
Implements: Collidable

The Physics Body is linked to a single game object. All physics operations should be performed against the body rather than the object itself. For example you can set the velocity, acceleration, bounce values etc all on the Body.

Instance Members

arcade
data: Dynamic

A property to hold any data related to this body. Can be useful if building a larger system on top of this one.


arcade
index: Int

A property to hold any index value related to this body. Can be useful if building a larger system on top of this one.


arcade
groups: Array<Group>

The list of groups that contain this body (can be null if there are no groups).


arcade
group: Group

A "main" group associated with this body.


arcade
enable: Bool

A disabled body won't be checked for any form of collision or overlap or have its pre/post updates run.


arcade
forceX: Bool

If true World.separate will always separate on the X axis before Y when this body is involved. Otherwise it will check gravity totals first.


arcade
isCircle: Bool

If true this Body is using circular collision detection. If false it is using rectangular. Use Body.setCircle to control the collision shape this Body uses.


arcade
radius: Float

The radius of the circular collision shape this Body is using if Body.setCircle has been enabled. If you wish to change the radius then call setCircle again with the new value. If you wish to stop the Body using a circle then call setCircle with a radius of zero (or undefined). The actual radius of the Body is equal to halfWidth and the diameter is equal to width.


arcade
x: Float

The x position of the physics body.


arcade
y: Float

The y position of the physics body.


arcade
prevX: Float

The previous x position of the physics body.


arcade
prevY: Float

The previous y position of the physics body.


arcade
allowRotation: Bool

Allow this Body to be rotated? (via angularVelocity, etc)


arcade
rotation: Float

The Body's rotation in degrees, as calculated by its angularVelocity and angularAcceleration. Please understand that the collision Body itself never rotates, it is always axis-aligned. However these values are passed up to the parent object and updates its rotation.


arcade
preRotation: Float

The previous rotation of the physics body, in degrees.


arcade
width: Float

The calculated width of the physics body.


arcade
height: Float

The calculated height of the physics body.


arcade
halfWidth: Float

The calculated width / 2 of the physics body.


arcade
halfHeight: Float

The calculated height / 2 of the physics body.


arcade
centerX: Float

The center x coordinate of the Physics Body.


arcade
centerY: Float

The center y coordinate of the Physics Body.


arcade
velocityX: Float

The x velocity, or rate of change of the Body's x position. Measured in pixels per second.


arcade
velocityY: Float

The y velocity, or rate of change of the Body's y position. Measured in pixels per second.


arcade
newVelocityX: Float

The x distance traveled during the last update, equal to velocityX * physicsElapsed. Calculated during the Body.preUpdate and applied to its position.


arcade
newVelocityY: Float

The y distance traveled during the last update, equal to velocityY * physicsElapsed. Calculated during the Body.preUpdate and applied to its position.


arcade
maxDeltaX: Float

The maximum x delta value. The Body position is updated based on the delta x/y values. You can set a cap on those (both +-) using maxDeltaX.


arcade
maxDeltaY: Float

The maximum y delta value. The Body position is updated based on the delta x/y values. You can set a cap on those (both +-) using maxDeltaY.


arcade
accelerationX: Float

The x acceleration is the rate of change of the x velocity. Measured in pixels per second squared.


arcade
accelerationY: Float

The y acceleration is the rate of change of the y velocity. Measured in pixels per second squared.


arcade
allowDrag: Bool

Allow this Body to be influenced by drag?


arcade
dragX: Float

The x drag applied to the motion of the Body (when allowDrag is enabled). Measured in pixels per second squared.


arcade
dragY: Float

The y drag applied to the motion of the Body (when allowDrag is enabled). Measured in pixels per second squared.


arcade
allowGravity: Bool

Allow this Body to be influenced by gravity? Either world or local.


arcade
gravityX: Float

This Body's local x gravity, added to any world x gravity, unless Body.allowGravity is set to false.


arcade
gravityY: Float

This Body's local y gravity, added to any world y gravity, unless Body.allowGravity is set to false.


arcade
bounceX: Float

The x elasticity of the Body when colliding. bounceX = 1 means full rebound, bounceX = 0.5 means 50% rebound velocity.


arcade
bounceY: Float

The y elasticity of the Body when colliding. bounceY = 1 means full rebound, bounceY = 0.5 means 50% rebound velocity.


arcade
useWorldBounce: Bool

The elasticity of the Body when colliding with the World bounds. By default this property is false, in which case Body.bounce is used instead. Set this property to true in order to enable a World bounds specific bounce value.


arcade
worldBounceX: Float

The x elasticity of the Body when colliding with the World bounds.


arcade
worldBounceY: Float

The y elasticity of the Body when colliding with the World bounds.


arcade
maxVelocityX: Float

The maximum x velocity (in pixels per second) that the Body can reach.


arcade
maxVelocityY: Float

The maximum y velocity (in pixels per second) that the Body can reach.


arcade
frictionX: Float

If this Body is immovable and moving, and another Body is 'riding' this one, this is the amount of x motion the riding Body receives.


arcade
frictionY: Float

If this Body is immovable and moving, and another Body is 'riding' this one, this is the amount of y motion the riding Body receives.


arcade
angularVelocity: Float

The angular velocity is the rate of change of the Body's rotation. It is measured in degrees per second.


arcade
angularAcceleration: Float

The angular acceleration is the rate of change of the angular velocity. Measured in degrees per second squared.


arcade
angularDrag: Float

The drag applied during the rotation of the Body. Measured in degrees per second squared.


arcade
maxAngularVelocity: Float

The maximum angular velocity in degrees per second that the Body can reach.


arcade
mass: Float

The mass of the Body. When two bodies collide their mass is used in the calculation to determine the exchange of velocity.


arcade
angle: Float

The angle of the Body's velocity in radians.


arcade
speed: Float

The speed of the Body in pixels per second, equal to the magnitude of the velocity.


arcade
facing: Direction

A const reference to the direction the Body is traveling or facing: NONE, LEFT, RIGHT, UP, or DOWN. If the Body is moving on both axes, UP and DOWN take precedence.


arcade
immovable: Bool

An immovable Body will not receive any impacts from other bodies. Two immovable Bodies can't separate or exchange momentum and will pass through each other.


arcade
moves: Bool

Whether the physics system should update the Body's position and rotation based on its velocity, acceleration, drag, and gravity.

If you have a Body that is being moved around the world via a tween or a Group motion, but its local x/y position never actually changes, then you should set Body.moves = false. Otherwise it will most likely fly off the screen. If you want the physics system to move the body around, then set moves to true.

A Body with moves = false can still be moved slightly (but not accelerated) during collision separation unless you set immovable as well.


arcade
customSeparateX: Bool

This flag allows you to disable the custom x separation that takes place by World.separate. Used in combination with your own collision processHandler you can create whatever type of collision response you need.


arcade
customSeparateY: Bool

This flag allows you to disable the custom y separation that takes place by World.separate. Used in combination with your own collision processHandler you can create whatever type of collision response you need.


arcade
overlapX: Float

When this body collides with another, the amount of horizontal overlap is stored here.


arcade
overlapY: Float

When this body collides with another, the amount of vertical overlap is stored here.


arcade
overlapR: Float

If Body.isCircle is true, and this body collides with another circular body, the amount of overlap is stored here.


arcade
embedded: Bool

If a body is overlapping with another body, but neither of them are moving (maybe they spawned on-top of each other?) this is set to true.


arcade
collideWorldBounds: Bool

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.


arcade
checkCollisionNone: Bool

If true, collision and overlap checks are disabled for this Body, but motion is retained.


arcade
checkCollisionUp: Bool

Whether this body processes collisions on its top edge.


arcade
checkCollisionDown: Bool

Whether this body processes collisions on its bottom edge.


arcade
checkCollisionLeft: Bool

Whether this body processes collisions on its left edge.


arcade
checkCollisionRight: Bool

Whether this body processes collisions on its right edge.


arcade
touchingNone: Bool

True if the Body is not touching any other Body.


arcade
touchingUp: Bool

True if the Body is touching another Body on its top edge.


arcade
touchingDown: Bool

True if the Body is touching another Body on its bottom edge.


arcade
touchingLeft: Bool

True if the Body is touching another Body on its left edge.


arcade
touchingRight: Bool

True if the Body is touching another Body on its right edge.


arcade
wasTouchingNone: Bool

True if the Body was not touching any other Body in the previous collision check.


arcade
wasTouchingUp: Bool

True if the Body was touching another Body on its top edge in the previous collision check.


arcade
wasTouchingDown: Bool

True if the Body was touching another Body on its bottom edge in the previous collision check.


arcade
wasTouchingLeft: Bool

True if the Body was touching another Body on its left edge in the previous collision check.


arcade
wasTouchingRight: Bool

True if the Body was touching another Body on its right edge in the previous collision check.


arcade
blockedNone: Bool

If this Body being blocked by world bounds or another immovable object?


arcade
blockedUp: Bool

If this Body being blocked by upper world bounds or another immovable object above it?


arcade
blockedDown: Bool

If this Body being blocked by lower world bounds or another immovable object below it?


arcade
blockedLeft: Bool

If this Body being blocked by left world bounds or another immovable object on the left?


arcade
blockedRight: Bool

If this Body being blocked by right world bounds or another immovable object on the right?


arcade
dirty: Bool

If this Body in a preUpdate (true) or postUpdate (false) state?


arcade
skipQuadTree: Bool

If true and you collide this Body against a Group, it will disable the collision check from using a QuadTree.


arcade
isMoving: Bool

Set by the moveTo and moveFrom methods.


arcade
stopVelocityOnCollide: Bool

Set by the moveTo and moveFrom methods.


arcade
dx: Float

arcade
dy: Float

arcade
left: Float

arcade
top: Float


arcade
bottom: Float

arcade
onWorldBounds(: Body, : Bool, : Bool, : Bool, : Bool): Void

A callback that is dispatched when this Body collides with the world bounds. Due to the potentially high volume of signals this could create it is disabled by default. To use this feature set this property to a function and it will be called when a collision happens, passing five arguments: onWorldBounds(body, up, down, left, right) where the Body is a reference to this Body, and the other arguments are booleans indicating on which side of the world the Body collided.

Name Type
`` Body
`` Bool
`` Bool
`` Bool
`` Bool

arcade
onCollide(: Body, : Body): Void

A callback that is dispatched when this Body collides with another Body.

You still need to call world.collide in your update method in order for this callback to be dispatched.

Usually you'd pass a callback to the collide method, but this callback provides for a different level of notification.

Due to the potentially high volume of callbacks this could create it is disabled by default.

To use this feature set this property to a function and it will be called when a collision happens, passing two arguments: the bodies which collided. The first body in the argument is always this Body.

If two Bodies with this callback set collide, both will dispatch the callback.

Name Type
`` Body
`` Body

arcade
onOverlap(: Body, : Body): Void

A callback that is dispatched when this Body overlaps with another Body.

You still need to call world.overlap in your update method in order for this callback to be dispatched.

Usually you'd pass a callback to the overlap method, but this callback provides for a different level of notification.

Due to the potentially high volume of callbacks this could create it is disabled by default.

To use this feature set this property to a function and it will be called when an overlap happens, passing two arguments: the bodies which overlapped. The first body in the argument is always this Body.

If two Bodies with this callback set overlap, both will dispatch the callback.

Name Type
`` Body
`` Body

arcade
onMoveComplete(: Body, : Bool): Void

Listen for the completion of moveTo or moveFrom events.

Name Type
`` Body
`` Bool

arcade
movementCallback(body: Body, velocityX: Float, velocityY: Float, percent: Float): Bool

Optional callback. If set, invoked during the running of moveTo or moveFrom events. Note: this is not an event (emit{X}) because we are expecting a boolean return value.

Name Type
body Body
velocityX Float
velocityY Float
percent Float
Returns
Bool

arcade
updateHalfSize(): Void

arcade
updateCenter(): Void

Update the Body's center from its position.


arcade
updateSize(width: Float, height: Float): Void
Name Type
width Float
height Float

arcade
stopMovement(stopVelocity: Bool): Void

If this Body is moving as a result of a call to moveTo or moveFrom (i.e. it has Body.isMoving true), then calling this method will stop the movement before either the duration or distance counters expire.

The onMoveComplete callback is dispatched.

Name Type Description
stopVelocity Bool Should the Body.velocity be set to zero?

arcade
moveFrom(duration: Float, ?speed: Float = -999999999.0, ?direction: Float = -999999999.0): Bool

Note: This method is experimental, and may be changed or removed in a future release.

This method moves the Body in the given direction, for the duration specified. It works by setting the velocity on the Body, and an internal timer, and then monitoring the duration each frame. When the duration is up the movement is stopped and the Body.onMoveComplete callback is dispatched.

Movement also stops if the Body collides or overlaps with any other Body.

You can control if the velocity should be reset to zero on collision, by using the property Body.stopVelocityOnCollide.

Stop the movement at any time by calling Body.stopMovement.

You can optionally set a speed in pixels per second. If not specified it will use the current Body.speed value. If this is zero, the function will return false.

Please note that due to browser timings you should allow for a variance in when the duration will actually expire. Depending on system it may be as much as +- 50ms. Also this method doesn't take into consideration any other forces acting on the Body, such as Gravity, drag or maxVelocity, all of which may impact the movement.

Name Type Default Description
duration Float The duration of the movement, in seconds.
speed Float -999999999.0 The speed of the movement, in pixels per second. If not provided Body.speed is used.
direction Float -999999999.0 The angle of movement in degrees. If not provided Body.angle is used.
Returns Description
Bool True if the movement successfully started, otherwise false.

arcade
moveTo(duration: Float, distance: Float, ?direction: Float = -999999999.0): Bool

Note: This method is experimental, and may be changed or removed in a future release.

This method moves the Body in the given direction, for the duration specified. It works by setting the velocity on the Body, and an internal distance counter. The distance is monitored each frame. When the distance equals the distance specified in this call, the movement is stopped, and the Body.onMoveComplete callback is dispatched.

Movement also stops if the Body collides or overlaps with any other Body.

You can control if the velocity should be reset to zero on collision, by using the property Body.stopVelocityOnCollide.

Stop the movement at any time by calling Body.stopMovement.

Please note that due to browser timings you should allow for a variance in when the distance will actually expire.

Note: This method doesn't take into consideration any other forces acting on the Body, such as Gravity, drag or maxVelocity, all of which may impact the movement.

Name Type Default Description
duration Float The duration of the movement, in seconds.
distance Float The distance, in pixels, the Body will move.
direction Float -999999999.0 The angle of movement. If not provided Body.angle is used.
Returns Description
Bool True if the movement successfully started, otherwise false.

arcade
setCircle(radius: Float): Void

Sets this Body as using a circle, of the given radius, for all collision detection instead of a rectangle. The radius is given in pixels and is the distance from the center of the circle to the edge.

To change a Body back to being rectangular again call setSize.

Note: Circular collision only happens with other Arcade Physics bodies, it does not work against tile maps, where rectangular collision is the only method supported.

Name Type Description
radius Float The radius of the Body in pixels. Pass a value of zero / undefined, to stop the Body using a circle for collision.

arcade
reset(x: Float, y: Float, width: Float, height: Float, ?rotation: Float = 0): Void

Resets all Body values (velocity, acceleration, rotation, etc)

Name Type Default Description
x Float The new x position of the Body.
y Float The new y position of the Body.
width Float The new width of the Body.
height Float The new height of the Body.
rotation Float 0 The new rotation of the Body.

arcade
stop(): Void

Sets acceleration, velocity, and speed to 0.


arcade
hitTest(x: Float, y: Float): Bool

Tests if a world point lies within this Body.

Name Type Description
x Float The world x coordinate to test.
y Float The world y coordinate to test.
Returns Description
Bool True if the given coordinates are inside this Body, otherwise false.

arcade
isOnFloor(): Bool

Returns true if the bottom of this Body is in contact with either the world bounds or a tile.

Returns Description
Bool True if in contact with either the world bounds or a tile.

arcade
isOnCeiling(): Bool

Returns true if the top of this Body is in contact with either the world bounds or a tile.

Returns Description
Bool True if in contact with either the world bounds or a tile.

arcade
isOnWall(): Bool

Returns true if either side of this Body is in contact with either the world bounds or a tile.

Returns Description
Bool True if in contact with either the world bounds or a tile.

arcade
deltaAbsX(): Float

Returns the absolute delta x value.

Returns Description
Float The absolute delta value.

arcade
deltaAbsY(): Float

Returns the absolute delta y value.

Returns Description
Float The absolute delta value.

arcade
deltaX(): Float

Returns the delta x value. The difference between Body.x now and in the previous step.

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

arcade
deltaY(): Float

Returns the delta y value. The difference between Body.y now and in the previous step.

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

arcade
deltaZ(): Float

Returns the delta z value. The difference between Body.rotation now and in the previous step.

Returns Description
Float The delta value. Positive if the motion was clockwise, negative if anti-clockwise.

arcade
destroy(): Void

Destroys this Body.

First it removes this body from any groups it belongs to. Then it nulls the data reference.


arcade
setVelocityToPolar(azimuth: Float, ?radius: Float = 1, ?asDegrees: Bool = false): Void
Name Type Default
azimuth Float
radius Float 1
asDegrees Bool false

arcade
setAccelerationToPolar(azimuth: Float, ?radius: Float = 1, ?asDegrees: Bool = false): Void
Name Type Default
azimuth Float
radius Float 1
asDegrees Bool false

arcade
new(x: Float, y: Float, width: Float, height: Float, ?rotation: Float = 0): Void
Name Type Default
x Float
y Float
width Float
height Float
rotation Float 0

Private Members

arcade
moveTimer: Float

Internal time used by the moveTo and moveFrom methods.


arcade
moveDistance: Int

Internal distance value, used by the moveTo and moveFrom methods.


arcade
moveDuration: Float

Internal duration value, used by the moveTo and moveFrom methods.


arcade
moveTarget: Line

Set by the moveTo method, and updated each frame.


arcade
moveEnd: Point

Set by the moveTo method, and updated each frame.


arcade
circleContains(body: Body, x: Float, y: Float): Bool

Return true if the given x/y coordinates are within the circular body.

Name Type Description
body Body The Body to be checked.
x Float The X value of the coordinate to test.
y Float The Y value of the coordinate to test.
Returns Description
Bool True if the coordinates are within this circle, otherwise false.

arcade
rectangleContains(body: Body, x: Float, y: Float): Bool

Determines whether the specified coordinates are contained within the region defined by this rectangular body.

Name Type Description
body Body The Body object.
x Float The x coordinate of the point to test.
y Float The y coordinate of the point to test.
Returns Description
Bool A value of true if the Body contains the specified point; otherwise false.

arcade
degToRad(deg: Float): Float
Name Type
deg Float
Returns
Float

arcade
radToDeg(rad: Float): Float
Name Type
rad Float
Returns
Float

arcade
updateMovement(world: World): Bool

Internal method.

Name Type
world World
Returns
Bool

arcade
checkWorldBounds(world: World): Bool

Internal method.

Name Type
world World
Returns Description
Bool True if the Body collided with the world bounds, otherwise false.

arcade
toString(): String
Returns
String

Metadata

Name Parameters
:allow arcade.World