Phaser API Documentation

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

Phaser . Physics . Arcade . StaticBody

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

Phaser . Physics . Arcade . StaticBody

A Static Arcade Physics Body.

A Static Body never moves, and isn't automatically synchronized with its parent Game Object. That means if you make any change to the parent's origin, position, or scale after creating or adding the body, you'll need to update the Static Body manually.

A Static Body can collide with other Bodies, but is never moved by collisions.

Its dynamic counterpart is Phaser.Physics.Arcade.Body.

Constructor:

new StaticBody(world, gameObject)

Parameters:

name type description
world Phaser.Physics.Arcade.World

The Arcade Physics simulation this Static Body belongs to.

gameObject Phaser.GameObjects.GameObject

The Game Object this Static Body belongs to.

Since: 3.0.0

Members

<private> _dx: number
Focus
Focus

Description:

The calculated change in the Static Body's horizontal position during the current step. For a static body this is always zero.

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

Description:

The calculated change in the Static Body's vertical position during the current step. For a static body this is always zero.

Type:
number
Default: 0
Since: 3.10.0
Focus
Focus
<readonly> allowGravity: boolean
Focus
Focus

Description:

A constant false value expected by the Arcade Physics simulation.

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus

Description:

This property is kept for compatibility with Dynamic Bodies. Avoid using it.

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

Description:

The lowest y coordinate of the area of the StaticBody. (y + height)

Type:
number
Since: 3.0.0
Focus
Focus
<readonly> bounce: Phaser.Math.Vector2
Focus
Focus

Description:

Rebound, or restitution, following a collision, relative to 1. Always zero for a Static Body.

Type:
Since: 3.0.0
Focus
Focus

Description:

The center of the Static Body's boundary. This is the midpoint of its position (top-left corner) and its bottom-right corner.

Type:
Since: 3.0.0
Focus
Focus

Description:

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

Type:
Since: 3.0.0
Focus
Focus
<readonly> collideWorldBounds: boolean
Focus
Focus

Description:

Whether this StaticBody interacts with the world boundary. Always false for a Static Body. (Static Bodies never collide with the world boundary.)

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

Description:

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

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

Description:

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

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

Description:

The color of this Static Body on the debug display.

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

Description:

Whether the Static Body's boundary is drawn to the debug display.

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

Description:

Whether this StaticBody has ever overlapped with another while both were not moving.

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

Description:

Whether this Static Body is updated by the physics simulation.

Type:
boolean
Default: true
Since: 3.0.0
Focus
Focus

Description:

The Game Object this Static Body belongs to.

Type:
Since: 3.0.0
Focus
Focus
<readonly> gravity: Phaser.Math.Vector2
Focus
Focus

Description:

Gravitational force applied specifically to this Body. Values are in pixels per second squared. Always zero for a Static Body.

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

Description:

Half the Static Body's height, in pixels. If the Static Body is circular, this is also the Static Body's radius.

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

Description:

Half the Static Body's width, in pixels. If the Static Body is circular, this is also the Static Body's radius.

Type:
number
Since: 3.0.0
Focus
Focus
height: number
Focus
Focus

Description:

The height of the Static Body's boundary, in pixels. If the Static Body is circular, this is also the Static Body's diameter.

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

Description:

Whether this object can be moved by collisions with another body.

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

Description:

Whether this Static Body's boundary is circular (true) or rectangular (false).

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

Description:

Returns the left-most x coordinate of the area of the StaticBody.

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

Description:

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

Type:
number
Default: 1
Since: 3.0.0
Focus
Focus
<readonly> offset: Phaser.Math.Vector2
Focus
Focus

Description:

The offset set by Phaser.Physics.Arcade.StaticBody#setCircle or Phaser.Physics.Arcade.StaticBody#setSize.

This doesn't affect the Static Body's position, because a Static Body does not follow its Game Object.

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

Description:

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

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

Description:

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

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
<readonly> onWorldBounds: boolean
Focus
Focus

Description:

Whether the simulation emits a worldbounds event when this StaticBody collides with the world boundary. Always false for a Static Body. (Static Bodies never collide with the world boundary and never trigger a worldbounds event.)

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

Description:

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

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

Description:

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

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

Description:

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

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

Description:

The StaticBody's physics type (static by default).

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

Description:

The position of this Static Body within the simulation.

Type:
Since: 3.0.0
Focus
Focus
pushable: boolean
Focus
Focus

Description:

Sets if this Body can be pushed by another Body.

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

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

By default, Static Bodies are not pushable.

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

Description:

If this Static Body is circular, this is the radius of the boundary, as set by Phaser.Physics.Arcade.StaticBody#setCircle, in pixels. Equal to halfWidth.

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

Description:

The highest y coordinate of the area of the StaticBody.

Type:
number
Since: 3.0.0
Focus
Focus

Description:

This property is kept for compatibility with Dynamic Bodies. Avoid using it.

Type:
Since: 3.0.0
Focus
Focus
<readonly> velocity: Phaser.Math.Vector2
Focus
Focus

Description:

A constant zero velocity used by the Arcade Physics simulation for calculations.

Type:
Since: 3.0.0
Focus
Focus

Description:

This property is kept for compatibility with Dynamic Bodies. Avoid using it. The values are always false for a Static Body.

Type:
Since: 3.0.0
Focus
Focus
width: number
Focus
Focus

Description:

The width of the Static Body's boundary, in pixels. If the Static Body is circular, this is also the Static Body's diameter.

Type:
number
Since: 3.0.0
Focus
Focus

Description:

The Arcade Physics simulation this Static Body belongs to.

Type:
Since: 3.0.0
Focus
Focus
x: number
Focus
Focus

Description:

The x coordinate of the StaticBody.

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

Description:

The y coordinate of the StaticBody.

Type:
number
Since: 3.0.0
Focus
Focus

Methods

deltaAbsX()
Focus
Focus

Description:

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

Returns:
Description:

Always zero for a Static Body.

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

Description:

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

Returns:
Description:

Always zero for a Static Body.

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

Description:

The change in this StaticBody's horizontal position from the previous step. Always zero.

Returns:
Description:

The change in this StaticBody's velocity from the previous step. Always zero.

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

Description:

The change in this StaticBody's vertical position from the previous step. Always zero.

Returns:
Description:

The change in this StaticBody's velocity from the previous step. Always zero.

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

Description:

The change in this StaticBody's rotation from the previous step. Always zero.

Returns:
Description:

The change in this StaticBody's rotation from the previous step. Always zero.

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

Description:

Disables this Body and marks it for destruction during the next step.

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

Description:

Draws a graphical representation of the StaticBody for visual debugging purposes.

Parameters:

name type description
graphic Phaser.GameObjects.Graphics

The Graphics object to use for the debug drawing of the StaticBody.

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

Description:

Returns the x and y coordinates of the top left and bottom right points of the StaticBody.

Parameters:

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

The object which will hold the coordinates of the bounds.

Returns:
Description:

The same object that was passed with x, y, right and bottom values matching the respective values of the StaticBody.

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

Description:

Checks to see if a given x,y coordinate is colliding with this Static Body.

Parameters:

name type description
x number

The x coordinate to check against this body.

y number

The y coordinate to check against this body.

Returns:
Description:

true if the given coordinate lies within this body, otherwise false.

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

Description:

NOOP

Examples:
Since: 3.12.0
Focus
Focus
reset([x], [y])
Focus
Focus

Description:

Resets this Body to the given coordinates. Also positions its parent Game Object to the same coordinates.

Parameters:

name type arguments description
x number <optional>

The x coordinate to reset the body to. If not given will use the parent Game Object's coordinate.

y number <optional>

The y coordinate to reset the body to. If not given will use the parent Game Object's coordinate.

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

Description:

Sets this Static Body to have a circular body and sets its size and position.

Parameters:

name type arguments description
radius number

The radius of the StaticBody, in pixels.

offsetX number <optional>

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

offsetY number <optional>

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

Returns:
Description:

This Static Body object.

Examples:
Since: 3.0.0
Focus
Focus
setGameObject(gameObject, [update])
Focus
Focus

Description:

Changes the Game Object this Body is bound to. First it removes its reference from the old Game Object, then sets the new one. You can optionally update the position and dimensions of this Body to reflect that of the new Game Object.

Parameters:

name type arguments Default description
gameObject Phaser.GameObjects.GameObject

The new Game Object that will own this Body.

update boolean <optional> true

Reposition and resize this Body to match the new Game Object?

Returns:
Description:

This Static Body object.

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

Description:

Sets the Mass of the StaticBody. Will set the Mass to 0.1 if the value passed is less than or equal to zero.

Parameters:

name type description
value number

The value to set the Mass to. Values of zero or less are changed to 0.1.

Returns:
Description:

This Static Body object.

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

Description:

Positions the Static Body at an offset from its Game Object.

Parameters:

name type description
x number

The horizontal offset of the Static Body from the Game Object's x.

y number

The vertical offset of the Static Body from the Game Object's y.

Returns:
Description:

This Static Body object.

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

Description:

Sets the size of the Static Body. When center is true, also repositions it. Resets the width and height to match current frame, if no width and height provided and a frame is found.

Parameters:

name type arguments Default description
width number <optional>

The width of the Static 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 Static 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

Place the Static Body's center on its Game Object's center. Only works if the Game Object has the getCenter method.

Returns:
Description:

This Static Body object.

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

Description:

NOOP function. A Static Body cannot be stopped.

Returns:
Description:

This Static Body object.

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

Description:

Updates the StaticBody's center from its position and dimensions.

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

Description:

Syncs the Static Body's position and size with its parent Game Object.

Returns:
Description:

This Static Body object.

Examples:
Since: 3.1.0
Focus
Focus
willDrawDebug()
Focus
Focus

Description:

Indicates whether the StaticBody is going to be showing a debug visualization during postUpdate.

Returns:
Description:

Whether or not the StaticBody is going to show the debug visualization during postUpdate.

Type:
  • boolean
Examples:
Since: 3.0.0
Focus
Focus