The Physics Body is linked to a single Sprite. All physics operations should be performed against the body rather than the Sprite itself. For example you can set the velocity, acceleration, bounce values etc all on the Body. @class Phaser.Physics.Arcade.Body @constructor * @param {Phaser.Sprite} sprite - The Sprite object this physics body belongs to.

Constructor

@:value({ rotation : 0 })new(x:Float, y:Float, width:Float, height:Float, rotation:Float = 0)

Variables

@:value(null)data:Dynamic = null

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

@:value(-1)index:Int = -1

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

@:value(null)@:allow(arcade.Group)read onlygroups:Array<Group> = null

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

@:value(null)group:Group = null

A "main" group associated with this body.

@:value(true)enable:Bool = true

@property {boolean} enable - A disabled body won't be checked for any form of collision or overlap or have its pre/post updates run. @default

@:value(false)forceX:Bool = false

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.

@:value(false)isCircle:Bool = false

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. @property {boolean} isCircle @default @readOnly

@:value(0)radius:Float = 0

The radius of the circular collision shape this Body is using if Body.setCircle has been enabled, relative to the Sprite's texture. If you wish to change the radius then call {@link #setCircle} again with the new value. If you wish to stop the Body using a circle then call {@link #setCircle} with a radius of zero (or undefined). The actual radius of the Body (at any Sprite scale) is equal to {@link #halfWidth} and the diameter is equal to {@link #width}. @property {number} radius @default @readOnly

@:value(0)x:Float = 0

@:value(0)y:Float = 0

@:value(0)prevX:Float = 0

@:value(0)prevY:Float = 0

@:value(true)allowRotation:Bool = true

@property {boolean} allowRotation - Allow this Body to be rotated? (via angularVelocity, etc) @default

@:value(0)rotation:Float = 0

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 Sprite and updates its rotation. @property {number} rotation

@:value(0)preRotation:Float = 0

@property {number} preRotation - The previous rotation of the physics body, in degrees. @readonly

@:value(0)width:Float = 0

@property {number} width - The calculated width of the physics body. @readonly

@:value(0)height:Float = 0

@property {number} height - The calculated height of the physics body. @readonly

@:value(0)halfWidth:Float = 0

@property {number} halfWidth - The calculated width / 2 of the physics body. @readonly

@:value(0)halfHeight:Float = 0

@property {number} halfHeight - The calculated height / 2 of the physics body. @readonly

@:value(0)centerX:Float = 0

@:value(0)centerY:Float = 0

@:value(0)velocityX:Float = 0

@:value(0)velocityY:Float = 0

@:value(0)newVelocityX:Float = 0

@property {Phaser.Point} newVelocity - The distanced traveled during the last update, equal to velocity * physicsElapsed. Calculated during the Body.preUpdate and applied to its position. @readonly

@:value(0)newVelocityY:Float = 0

@:value(0)maxDeltaX:Float = 0

@:value(0)maxDeltaY:Float = 0

@:value(0)accelerationX:Float = 0

@:value(0)accelerationY:Float = 0

@:value(true)allowDrag:Bool = true

@property {boolean} allowDrag - Allow this Body to be influenced by {@link #drag}? @default

@:value(0)dragX:Float = 0

@:value(0)dragY:Float = 0

@:value(true)allowGravity:Bool = true

@property {boolean} allowGravity - Allow this Body to be influenced by gravity? Either world or local. @default

@:value(0)gravityX:Float = 0

@:value(0)gravityY:Float = 0

@:value(0)bounceX:Float = 0

@:value(0)bounceY:Float = 0

@:value(false)useWorldBounce:Bool = false

The elasticity of the Body when colliding with the World bounds. By default this property is null, in which case Body.bounce is used instead. Set this property to a Phaser.Point object in order to enable a World bounds specific bounce value. @property {Phaser.Point} useWorldBounce

@:value(0)worldBounceX:Float = 0

@:value(0)worldBounceY:Float = 0

@:value(null)onWorldBounds:(Body, Bool, Bool, Bool, Bool) ‑> Void = null

A Signal 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 Phaser.Signal: sprite.body.onWorldBounds = new Phaser.Signal() and it will be called when a collision happens, passing five arguments: onWorldBounds(sprite, up, down, left, right) where the Sprite is a reference to the Sprite that owns this Body, and the other arguments are booleans indicating on which side of the world the Body collided. @property {Phaser.Signal} onWorldBounds

@:value(null)onCollide:(Body, Body) ‑> Void = null

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

You still need to call game.physics.arcade.collide in your update method in order for this signal to be dispatched.

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

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 Phaser.Signal: sprite.body.onCollide = new Phaser.Signal() and it will be called when a collision happens, passing two arguments: the sprites which collided. The first sprite in the argument is always the owner of this Body.

If two Bodies with this Signal set collide, both will dispatch the Signal. @property {Phaser.Signal} onCollide

@:value(null)onOverlap:(Body, Body) ‑> Void = null

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

You still need to call game.physics.arcade.overlap in your update method in order for this signal to be dispatched.

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

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 Phaser.Signal: sprite.body.onOverlap = new Phaser.Signal() and it will be called when a collision happens, passing two arguments: the sprites which collided. The first sprite in the argument is always the owner of this Body.

If two Bodies with this Signal set collide, both will dispatch the Signal. @property {Phaser.Signal} onOverlap

@:value(10000)maxVelocityX:Float = 10000

@:value(10000)maxVelocityY:Float = 10000

@:value(1)frictionX:Float = 1

@:value(0)frictionY:Float = 0

@:value(0)angularVelocity:Float = 0

@property {number} angularVelocity - The angular velocity is the rate of change of the Body's rotation. It is measured in degrees per second. @default

@:value(0)angularAcceleration:Float = 0

@property {number} angularAcceleration - The angular acceleration is the rate of change of the angular velocity. Measured in degrees per second squared. @default

@:value(0)angularDrag:Float = 0

@property {number} angularDrag - The drag applied during the rotation of the Body. Measured in degrees per second squared. @default

@:value(1000)maxAngularVelocity:Float = 1000

@property {number} maxAngularVelocity - The maximum angular velocity in degrees per second that the Body can reach. @default

@:value(1)mass:Float = 1

@property {number} mass - The mass of the Body. When two bodies collide their mass is used in the calculation to determine the exchange of velocity. @default

@:value(0)angle:Float = 0

@property {number} angle - The angle of the Body's velocity in radians. @readonly

@:value(0)speed:Float = 0

@property {number} speed - The speed of the Body in pixels per second, equal to the magnitude of the velocity. @readonly

@:value(Direction.NONE)facing:Direction = Direction.NONE

@property {number} facing - A const reference to the direction the Body is traveling or facing: Phaser.NONE, Phaser.LEFT, Phaser.RIGHT, Phaser.UP, or Phaser.DOWN. If the Body is moving on both axes, UP and DOWN take precedence. @default

@:value(false)immovable:Bool = false

@property {boolean} immovable - 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. @default

@:value(true)moves:Bool = true

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 {@link #immovable} as well.

@property {boolean} moves - Set to true to allow the Physics system to move this Body, otherwise false to move it manually. @default

@:value(false)customSeparateX:Bool = false

This flag allows you to disable the custom x separation that takes place by Physics.Arcade.separate. Used in combination with your own collision processHandler you can create whatever type of collision response you need. @property {boolean} customSeparateX - Use a custom separation system or the built-in one? @default

@:value(false)customSeparateY:Bool = false

This flag allows you to disable the custom y separation that takes place by Physics.Arcade.separate. Used in combination with your own collision processHandler you can create whatever type of collision response you need. @property {boolean} customSeparateY - Use a custom separation system or the built-in one? @default

@:value(0)overlapX:Float = 0

When this body collides with another, the amount of overlap is stored here. @property {number} overlapX - The amount of horizontal overlap during the collision.

@:value(0)overlapY:Float = 0

When this body collides with another, the amount of overlap is stored here. @property {number} overlapY - The amount of vertical overlap during the collision.

@:value(0)overlapR:Float = 0

If Body.isCircle is true, and this body collides with another circular body, the amount of overlap is stored here. @property {number} overlapR - The amount of overlap during the collision.

@:value(false)embedded:Bool = false

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. @property {boolean} embedded - Body embed value.

@:value(false)collideWorldBounds:Bool = false

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. @property {boolean} collideWorldBounds - Should the Body collide with the World bounds?

@:value(false)checkCollisionNone:Bool = false

@:value(true)checkCollisionUp:Bool = true

@:value(true)checkCollisionDown:Bool = true

@:value(true)checkCollisionLeft:Bool = true

@:value(true)checkCollisionRight:Bool = true

@:value(true)touchingNone:Bool = true

@:value(false)touchingUp:Bool = false

@:value(false)touchingDown:Bool = false

@:value(false)touchingLeft:Bool = false

@:value(false)touchingRight:Bool = false

@:value(true)wasTouchingNone:Bool = true

@:value(false)wasTouchingUp:Bool = false

@:value(false)wasTouchingDown:Bool = false

@:value(false)wasTouchingLeft:Bool = false

@:value(false)wasTouchingRight:Bool = false

@:value(true)blockedNone:Bool = true

@property {boolean} blockedNone - If this Body being blocked by world bounds or another immovable object?

@:value(false)blockedUp:Bool = false

@property {boolean} blockedNone - If this Body being blocked by upper world bounds or another immovable object above it?

@:value(false)blockedDown:Bool = false

@property {boolean} blockedNone - If this Body being blocked by lower world bounds or another immovable object below it?

@:value(false)blockedLeft:Bool = false

@property {boolean} blockedNone - If this Body being blocked by left world bounds or another immovable object on the left?

@:value(false)blockedRight:Bool = false

@property {boolean} blockedNone - If this Body being blocked by right world bounds or another immovable object on the right?

@:value(false)dirty:Bool = false

@property {boolean} dirty - If this Body in a preUpdate (true) or postUpdate (false) state?

@:value(false)skipQuadTree:Bool = false

@property {boolean} skipQuadTree - If true and you collide this Sprite against a Group, it will disable the collision check from using a QuadTree.

@:value(false)isMoving:Bool = false

@property {boolean} isMoving - Set by the moveTo and moveFrom methods.

@:value(true)stopVelocityOnCollide:Bool = true

@property {boolean} stopVelocityOnCollide - Set by the moveTo and moveFrom methods.

@:value(null)onMoveComplete:(Body, Bool) ‑> Void = null

@property {Phaser.Signal} onMoveComplete - Listen for the completion of moveTo or moveFrom events.

@:value(null)movementCallback:(body:Body, velocityX:Float, velocityY:Float, percent:Float) ‑> Bool = null

@property {function} movementCallback - 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.

read onlydx:Float

read onlydy:Float

read onlyleft:Float

read onlytop:Float

read onlyright:Float

read onlybottom:Float

Methods

inlineupdateCenter():Void

Update the Body's center from its position.

@method Phaser.Physics.Arcade.Body#updateCenter @protected

inlineupdateSize(width:Float, height:Float):Void

inlinestopMovement(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 signal is dispatched.

@method Phaser.Physics.Arcade.Body#stopMovement

Parameters:

{boolean}

[stopVelocity] - Should the Body.velocity be set to zero?

@:value({ direction : -999999999.0, speed : -999999999.0 })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 signal 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.

@method Phaser.Physics.Arcade.Body#moveFrom

Parameters:

{number}

duration - The duration of the movement, in seconds.

{number}

[speed] - The speed of the movement, in pixels per second. If not provided Body.speed is used.

{number}

[direction] - The angle of movement in degrees. If not provided Body.angle is used.

Returns:

{boolean} True if the movement successfully started, otherwise false.

@:value({ direction : -999999999.0 })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 signal 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.

@method Phaser.Physics.Arcade.Body#moveTo

Parameters:

{float}

duration - The duration of the movement, in seconds.

{float}

distance - The distance, in pixels, the Body will move.

{float}

[direction] - The angle of movement. If not provided Body.angle is used.

Returns:

{boolean} True if the movement successfully started, otherwise false.

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 (relative to the Sprite's texture) and is the distance from the center of the circle to the edge.

You can also control the x and y offset, which is the position of the Body relative to the top-left of the Sprite's texture.

To change a Body back to being rectangular again call Body.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.

@method Phaser.Physics.Arcade.Body#setCircle

Parameters:

{number}

[radius] - The radius of the Body in pixels. Pass a value of zero / undefined, to stop the Body using a circle for collision.

@:value({ rotation : 0 })inlinereset(x:Float, y:Float, width:Float, height:Float, rotation:Float = 0):Void

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

@method Phaser.Physics.Arcade.Body#reset

Parameters:

{number}

x - The new x position of the Body.

{number}

y - The new y position of the Body.

inlinestop():Void

Sets acceleration, velocity, and {@link #speed} to 0.

@method Phaser.Physics.Arcade.Body#stop

inlinehitTest(x:Float, y:Float):Bool

Tests if a world point lies within this Body.

@method Phaser.Physics.Arcade.Body#hitTest

Parameters:

{number}

x - The world x coordinate to test.

{number}

y - The world y coordinate to test.

Returns:

{boolean} True if the given coordinates are inside this Body, otherwise false.

inlineisOnFloor():Bool

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

@method Phaser.Physics.Arcade.Body#onFloor

Returns:

{boolean} True if in contact with either the world bounds or a tile.

inlineisOnCeiling():Bool

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

@method Phaser.Physics.Arcade.Body#onCeiling

Returns:

{boolean} True if in contact with either the world bounds or a tile.

inlineisOnWall():Bool

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

@method Phaser.Physics.Arcade.Body#onWall

Returns:

{boolean} True if in contact with either the world bounds or a tile.

inlinedeltaAbsX():Float

Returns the absolute delta x value.

@method Phaser.Physics.Arcade.Body#deltaAbsX

Returns:

{number} The absolute delta value.

inlinedeltaAbsY():Float

Returns the absolute delta y value.

@method Phaser.Physics.Arcade.Body#deltaAbsY

Returns:

{number} The absolute delta value.

inlinedeltaX():Float

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

@method Phaser.Physics.Arcade.Body#deltaX

Returns:

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

inlinedeltaY():Float

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

@method Phaser.Physics.Arcade.Body#deltaY

Returns:

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

inlinedeltaZ():Float

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

@method Phaser.Physics.Arcade.Body#deltaZ

Returns:

{number} The delta value. Positive if the motion was clockwise, negative if anti-clockwise.

destroy():Void

Destroys this Body.

First it calls Group.removeFromHash if the Game Object this Body belongs to is part of a Group. Then it nulls the Game Objects body reference, and nulls this Body.sprite reference.

@method Phaser.Physics.Arcade.Body#destroy

@:value({ asDegrees : false, radius : 1 })inlinesetVelocityToPolar(azimuth:Float, radius:Float = 1, asDegrees:Bool = false):Void

@:value({ asDegrees : false, radius : 1 })inlinesetAccelerationToPolar(azimuth:Float, radius:Float = 1, asDegrees:Bool = false):Void