phaser - v4.0.0-rc.4
    Preparing search index...

    A Dynamic Arcade Body.

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

    Implements

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    acceleration: Math.Vector2

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

    allowDrag: boolean

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

    allowGravity: boolean

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

    allowRotation: boolean

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

    angle: number

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

    angularAcceleration: number

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

    angularDrag: number

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

    Angular drag is applied only when angular acceleration is zero.

    angularVelocity: number

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

    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.

    bottom: number

    The bottom edge of this Body.

    bounce: Math.Vector2

    Rebound following a collision, relative to 1.

    center: Math.Vector2

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

    checkCollision: ArcadeBodyCollision

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

    collideWorldBounds: boolean

    Whether this Body interacts with the world boundary.

    collisionCategory: number

    The Arcade Physics Body Collision Category.

    This can be set to any valid collision bitfield value.

    See the setCollisionCategory method for more details.

    collisionMask: number

    The Arcade Physics Body Collision Mask.

    See the setCollidesWith method for more details.

    customBoundsRectangle: 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.

    customSeparateX: boolean

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

    customSeparateY: boolean

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

    debugBodyColor: number

    The color of this Body on the debug display.

    debugShowBody: boolean

    Whether the Body is drawn to the debug display.

    debugShowVelocity: boolean

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

    deltaMax: Math.Vector2

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

    directControl: boolean

    Is this Body under direct control, outside of the physics engine? For example, are you trying to move it via a Tween? Or have it follow a path? If so then you can enable this boolean so that the Body will calculate its velocity based purely on its change in position each frame. This allows you to then tween the position and still have it collide with other objects. However, setting the velocity will have no impact on this Body while this is set.

    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.

    embedded: boolean

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

    enable: boolean

    Whether this Body is updated by the physics simulation.

    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.

    friction: 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.

    gameObject: GameObject

    The Game Object this Body belongs to.

    As of Phaser 3.60 this is now optional and can be undefined.

    gravity: 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.

    halfHeight: number

    Half the Body's height, in pixels.

    halfWidth: number

    Half the Body's width, in pixels.

    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.

    immovable: boolean

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

    isBody: boolean

    A quick-test flag that signifies this is a Body, used in the World collision handler.

    isCircle: boolean

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

    left: number

    The left edge of the Body. Identical to x.

    mass: number

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

    maxAngular: number

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

    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).

    maxVelocity: Math.Vector2

    The absolute maximum velocity of this body, in pixels per second. The horizontal and vertical components are applied separately.

    moves: boolean

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

    newVelocity: 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.

    offset: Math.Vector2

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

    onCollide: boolean

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

    onOverlap: boolean

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

    onWorldBounds: boolean

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

    overlapR: number

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

    overlapX: number

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

    overlapY: number

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

    physicsType: number

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

    position: Math.Vector2

    The position of this Body within the simulation.

    preRotation: number

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

    The position of this Body during the previous step.

    prevFrame: Math.Vector2

    The position of this Body during the previous frame.

    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.

    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.

    right: number

    The right edge of the Body.

    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.

    slideFactor: Math.Vector2

    The Slide Factor of this Body.

    The Slide Factor controls how much velocity is preserved when this Body is pushed by another Body.

    The default value is 1, which means that it will take on all velocity given in the push. You can adjust this value to control how much velocity is retained by this Body when the push ends.

    A value of 0, for example, will allow this Body to be pushed but then remain completely still after the push ends, such as you see in a game like Sokoban.

    Or you can set a mid-point, such as 0.25 which will allow it to keep 25% of the original velocity when the push ends. You can combine this with the setDrag() method to create deceleration.

    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.

    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.

    speed: number

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

    syncBounds: boolean

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

    top: number

    The top edge of the Body. Identical to y.

    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.

    transform: object

    Transformations applied to this Body.

    useDamping: boolean

    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.

    velocity: Math.Vector2

    The Body's velocity, in pixels per second.

    wasTouching: ArcadeBodyCollision

    This Body's touching value during the previous step.

    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.

    The Arcade Physics simulation this Body belongs to.

    worldBounce: Math.Vector2

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

    x: number

    The Bodys horizontal position (left edge).

    y: number

    The Bodys vertical position (top edge).

    Methods

    • Adds the given Collision Category to the list of those that this Arcade Physics Body will collide with.

      Parameters

      • category: number

        The collision category to add.

      Returns this

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

      Returns boolean

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

      Returns number

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

      Returns number

    • 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 number

    • 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 number

    • 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 number

    • 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 number

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

      Returns number

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

      Returns void

    • Tests if the coordinates are within this Body.

      Parameters

      • x: number

        The horizontal coordinate.

      • y: number

        The vertical coordinate.

      Returns boolean

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

      Returns boolean

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

      Returns boolean

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

      Returns boolean

    • Feeds the Body results back into the parent Game Object.

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

      Returns void

    • 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

      • willStep: boolean

        Will this Body run an update as well?

      • delta: number

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

      Returns void

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

      Parameters

      • x: number

        The amount to add to the Body position.

      • Optionalvx: number

        The amount to add to the Body velocity.

      • Optionalleft: boolean

        Set the blocked.left value?

      • Optionalright: boolean

        Set the blocked.right value?

      Returns void

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

      Parameters

      • y: number

        The amount to add to the Body position.

      • Optionalvy: number

        The amount to add to the Body velocity.

      • Optionalup: boolean

        Set the blocked.up value?

      • Optionaldown: boolean

        Set the blocked.down value?

      Returns void

    • Removes the given Collision Category from the list of those that this Arcade Physics Body will collide with.

      Parameters

      • category: number

        The collision category to add.

      Returns this

    • 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

      • x: number

        The horizontal position to place the Game Object.

      • y: number

        The vertical position to place the Game Object.

      Returns void

    • 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

      • Optionalclear: boolean

        Set the wasTouching values to their defaults. Default false.

      Returns void

    • Sets the Body's acceleration.

      Parameters

      • x: number

        The horizontal component, in pixels per second squared.

      • Optionaly: number

        The vertical component, in pixels per second squared. Default x.

      Returns Physics.Arcade.Body

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

      Parameters

      • Optionalbounds: Geom.Rectangle

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

      Returns this

    • Sizes and positions this Body, as a circle.

      Parameters

      • radius: number

        The radius of the Body, in source pixels.

      • OptionaloffsetX: number

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

      • OptionaloffsetY: number

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

      Returns Physics.Arcade.Body

    • Sets all of the Collision Categories that this Arcade Physics Body will collide with. You can either pass a single category value, or an array of them.

      Calling this method will reset all of the collision categories, so only those passed to this method are enabled.

      If you wish to add a new category to the existing mask, call the addCollisionCategory method.

      If you wish to reset the collision category and mask, call the resetCollisionCategory method.

      Parameters

      • categories: number | number[]

        The collision category to collide with, or an array of them.

      Returns this

    • Sets whether this Body collides with the world boundary.

      Optionally also sets the World Bounce and onWorldBounds values.

      Parameters

      • Optionalvalue: boolean

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

      • OptionalbounceX: number

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

      • OptionalbounceY: number

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

      • OptionalonWorldBounds: boolean

        If given this replaces the Body's onWorldBounds value.

      Returns Physics.Arcade.Body

    • Sets the Collision Category that this Arcade Physics Body will use in order to determine what it can collide with.

      It can only have one single category assigned to it.

      If you wish to reset the collision category and mask, call the resetCollisionCategory method.

      Parameters

      • category: number

        The collision category.

      Returns this

    • 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

      • value: boolean

        true to use damping, or false to use drag.

      Returns Physics.Arcade.Body

    • Sets whether this Body should calculate its velocity based on its change in position every frame. The default, which is to not do this, means that you make this Body move by setting the velocity directly. However, if you are trying to move this Body via a Tween, or have it follow a Path, then you should enable this instead. This will allow it to still collide with other bodies, something that isn't possible if you're just changing its position directly.

      Parameters

      • Optionalvalue: boolean

        true if the Body calculate velocity based on changes in position, otherwise false. Default true.

      Returns Physics.Arcade.Body

    • Sets the Body's drag.

      Parameters

      • x: number

        The horizontal component, in pixels per second squared.

      • Optionaly: number

        The vertical component, in pixels per second squared. Default x.

      Returns Physics.Arcade.Body

    • Assign this Body to a new Game Object.

      Removes this body from the Physics World, assigns to the new Game Object, calls setSize and then adds this body back into the World again, setting it enabled, unless the enable argument is set to false.

      If this body already has a Game Object, then it will remove itself from that Game Object first.

      If the given gameObject doesn't have a body property, it is created and this Body is assigned to it.

      Parameters

      • gameObject: GameObject

        The Game Object to assign this Body to.

      • Optionalenable: boolean

        Automatically enable this Body for physics. Default true.

      Returns Physics.Arcade.Body

    • Sets the Body's gravity.

      Parameters

      • x: number

        The horizontal component, in pixels per second squared.

      • Optionaly: number

        The vertical component, in pixels per second squared. Default x.

      Returns Physics.Arcade.Body

    • Sets the Body's maximum velocity.

      Parameters

      • x: number

        The horizontal velocity, in pixels per second.

      • Optionaly: number

        The vertical velocity, in pixels per second. Default x.

      Returns Physics.Arcade.Body

    • 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

      • x: number

        The horizontal offset, in source pixels.

      • Optionaly: number

        The vertical offset, in source pixels. Default x.

      Returns Physics.Arcade.Body

    • 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

      • Optionalwidth: number

        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.

      • Optionalheight: number

        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.

      • Optionalcenter: boolean

        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. Default true.

      Returns Physics.Arcade.Body

    • Sets the Slide Factor of this Body.

      The Slide Factor controls how much velocity is preserved when this Body is pushed by another Body.

      The default value is 1, which means that it will take on all velocity given in the push. You can adjust this value to control how much velocity is retained by this Body when the push ends.

      A value of 0, for example, will allow this Body to be pushed but then remain completely still after the push ends, such as you see in a game like Sokoban.

      Or you can set a mid-point, such as 0.25 which will allow it to keep 25% of the original velocity when the push ends. You can combine this with the setDrag() method to create deceleration.

      Parameters

      • x: number

        The horizontal slide factor. A value between 0 and 1.

      • Optionaly: number

        The vertical slide factor. A value between 0 and 1. Default x.

      Returns Physics.Arcade.Body

    • 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

      • delta: number

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

      Returns void

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

      Returns void

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

      Returns void

    • 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.

      Returns void

    • Checks to see if the given Collision Category will collide with this Arcade Physics object or not.

      Parameters

      • category: number

        Collision category value to test.

      Returns boolean

    • Whether this Body will be drawn to the debug display.

      Returns boolean