Class: StaticBody

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 Body manually.

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

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


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
Source: src/physics/arcade/StaticBody.js (Line 13)

Members


<readonly> allowGravity :boolean

A constant false value expected by the Arcade Physics simulation.

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/physics/arcade/StaticBody.js (Line 188)

blocked :ArcadeBodyCollision

Whether this StaticBody has ever collided with a tile or the world boundary.

Type:
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 372)

<readonly> bottom :number

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

Type:
  • number
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 954)

<readonly> bounce :Phaser.Math.Vector2

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

Type:
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 209)

center :Phaser.Math.Vector2

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
Source: src/physics/arcade/StaticBody.js (Line 168)

checkCollision :ArcadeBodyCollision

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
Source: src/physics/arcade/StaticBody.js (Line 345)

<readonly> collideWorldBounds :boolean

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

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/physics/arcade/StaticBody.js (Line 333)

customSeparateX :boolean

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

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/physics/arcade/StaticBody.js (Line 273)

customSeparateY :boolean

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

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/physics/arcade/StaticBody.js (Line 283)

debugBodyColor :integer

The color of this Static Body on the debug display.

Type:
  • integer
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 68)

debugShowBody :boolean

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

Type:
  • boolean
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 59)

embedded :boolean

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

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/physics/arcade/StaticBody.js (Line 323)

enable :boolean

Whether this Static Body is updated by the physics simulation.

Type:
  • boolean
Since: 3.0.0
Default Value:
  • true
Source: src/physics/arcade/StaticBody.js (Line 77)

gameObject :Phaser.GameObjects.GameObject

The Game Object this Static Body belongs to.

Type:
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 50)

<readonly> gravity :Phaser.Math.Vector2

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
Source: src/physics/arcade/StaticBody.js (Line 199)

halfHeight :number

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
Source: src/physics/arcade/StaticBody.js (Line 158)

halfWidth :number

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
Source: src/physics/arcade/StaticBody.js (Line 148)

height :number

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
Source: src/physics/arcade/StaticBody.js (Line 138)

immovable :boolean

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

Type:
  • boolean
Since: 3.0.0
Default Value:
  • true
Source: src/physics/arcade/StaticBody.js (Line 263)

isCircle :boolean

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

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/physics/arcade/StaticBody.js (Line 87)

<readonly> left :number

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

Type:
  • number
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 903)

mass :number

The StaticBody'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/StaticBody.js (Line 253)

offset :Phaser.Math.Vector2

The offset of this Static Body's actual position from any updated position.

Unlike a dynamic Body, a Static Body does not follow its Game Object. As such, this offset is only applied when resizing the Static Body.

Type:
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 108)

onCollide :boolean

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

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/physics/arcade/StaticBody.js (Line 233)

onOverlap :boolean

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

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/physics/arcade/StaticBody.js (Line 243)

<readonly> onWorldBounds :boolean

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
Since: 3.0.0
Default Value:
  • false
Source: src/physics/arcade/StaticBody.js (Line 221)

overlapR :number

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

Type:
  • number
Since: 3.0.0
Default Value:
  • 0
Source: src/physics/arcade/StaticBody.js (Line 313)

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/StaticBody.js (Line 293)

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/StaticBody.js (Line 303)

physicsType :integer

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

Type:
  • integer
Since: 3.0.0
Default Value:
  • Phaser.Physics.Arcade.STATIC_BODY
Source: src/physics/arcade/StaticBody.js (Line 381)

position :Phaser.Math.Vector2

The position of this Static Body within the simulation.

Type:
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 119)

radius :number

If this Static Body is circular, this is the unscaled radius of the Static Body's boundary, 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/StaticBody.js (Line 97)

The right-most x coordinate of the area of the StaticBody.

Type:
  • number
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 920)

<readonly> top :number

The highest y coordinate of the area of the StaticBody.

Type:
  • number
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 937)

touching :ArcadeBodyCollision

Whether this StaticBody has ever collided with another body and in which direction.

Type:
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 354)

<readonly> velocity :Phaser.Math.Vector2

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

Type:
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 178)

wasTouching :ArcadeBodyCollision

Whether this StaticBody was colliding with another body during the last step or any previous step, and in which direction.

Type:
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 363)

width :number

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
Source: src/physics/arcade/StaticBody.js (Line 128)

world :Phaser.Physics.Arcade.World

The Arcade Physics simulation this Static Body belongs to.

Type:
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 41)

x :number

The x coordinate of the StaticBody.

Type:
  • number
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 853)

y :number

The y coordinate of the StaticBody.

Type:
  • number
Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 878)

Methods


deltaAbsX()

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

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 708)
Returns:

Always zero for a Static Body.

Type
number

deltaAbsY()

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

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 721)
Returns:

Always zero for a Static Body.

Type
number

deltaX()

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

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 734)
Returns:

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

Type
number

deltaY()

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

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 747)
Returns:

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

Type
number

deltaZ()

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

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 760)
Returns:

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

Type
number

destroy()

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

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 773)

drawDebug(graphic)

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.

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 786)

getBounds(obj)

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

Parameters:
Name Type Description
obj ArcadeBodyBounds

The object which will hold the coordinates of the bounds.

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 662)
Returns:

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

Type
ArcadeBodyBounds

hitTest(x, y)

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.

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 682)
Returns:

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

Type
boolean

postUpdate()

NOOP

Since: 3.12.0
Source: src/physics/arcade/StaticBody.js (Line 698)

reset( [x] [, y])

Resets this Body to the given coordinates. Also positions its parent Game Object to the same coordinates. Similar to updateFromGameObject, but doesn't modify the Body's dimensions.

Parameters:
Name Type Argument 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.

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 621)

setCircle(radius [, offsetX] [, offsetY])

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

Parameters:
Name Type Argument 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.

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 565)
Returns:

This Static Body object.

Type
Phaser.Physics.Arcade.StaticBody

setGameObject(gameObject [, update])

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 Argument 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?

Since: 3.1.0
Source: src/physics/arcade/StaticBody.js (Line 416)
See:
Returns:

This Static Body object.

Type
Phaser.Physics.Arcade.StaticBody

setMass(value)

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.

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 830)
Returns:

This Static Body object.

Type
Phaser.Physics.Arcade.StaticBody

setOffset(x, y)

Sets the offset of the body.

Parameters:
Name Type Description
x number

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

y number

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

Since: 3.4.0
Source: src/physics/arcade/StaticBody.js (Line 482)
Returns:

This Static Body object.

Type
Phaser.Physics.Arcade.StaticBody

setSize( [width] [, height] [, offsetX] [, offsetY])

Sets the size of the body. Resets the width and height to match current frame, if no width and height provided and a frame is found.

Parameters:
Name Type Argument Description
width integer <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 integer <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.

offsetX number <optional>

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

offsetY number <optional>

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

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 514)
Returns:

This Static Body object.

Type
Phaser.Physics.Arcade.StaticBody

stop()

NOOP function. A Static Body cannot be stopped.

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 649)
Returns:

This Static Body object.

Type
Phaser.Physics.Arcade.StaticBody

updateCenter()

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

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 610)

updateFromGameObject()

Updates this Static Body so that its position and dimensions are updated based on the current Game Object it is bound to.

Since: 3.1.0
Source: src/physics/arcade/StaticBody.js (Line 452)
Returns:

This Static Body object.

Type
Phaser.Physics.Arcade.StaticBody

willDrawDebug()

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

Since: 3.0.0
Source: src/physics/arcade/StaticBody.js (Line 817)
Returns:

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

Type
boolean