Phaser API Documentation

  Version: 
Filter

The Arcade Physics World.

The World is responsible for creating, managing, colliding and updating all of the bodies within it.

An instance of the World belongs to a Phaser.Scene and is accessed via the property physics.world.

Constructor:

new World(scene, config)

Parameters:

name type description
scene Phaser.Scene

The Scene to which this World instance belongs.

config Phaser.Types.Physics.Arcade.ArcadeWorldConfig

An Arcade Physics Configuration object.

Since: 3.0.0

Extends


Members

OVERLAP_BIAS: number
Focus
Focus

Description:

The maximum absolute difference of a Body's per-step velocity and its overlap with another Body that will result in separation on each axis. Larger values favor separation. Smaller values favor no separation.

Type:
number
Default: 4
Since: 3.0.0
Focus
Focus
TILE_BIAS: number
Focus
Focus

Description:

The maximum absolute value of a Body's overlap with a tile that will result in separation on each axis. Larger values favor separation. Smaller values favor no separation. The optimum value may be similar to the tile size.

Type:
number
Default: 16
Since: 3.0.0
Focus
Focus
<private> _elapsed: number
Focus
Focus

Description:

The amount of elapsed ms since the last frame.

Type:
number
Since: 3.10.0
Focus
Focus
<private> _frameTime: number
Focus
Focus

Description:

Internal frame time value.

Type:
number
Since: 3.10.0
Focus
Focus
<private> _frameTimeMS: number
Focus
Focus

Description:

Internal frame time ms value.

Type:
number
Since: 3.10.0
Focus
Focus

Description:

A temporary Transform Matrix used by bodies for calculations without them needing their own local copy.

Type:
Since: 3.12.0
Focus
Focus

Description:

A temporary Transform Matrix used by bodies for calculations without them needing their own local copy.

Type:
Since: 3.12.0
Focus
Focus
<private> _total: number
Focus
Focus

Description:

Temporary total of colliding Bodies.

Type:
number
Default: 0
Since: 3.0.0
Focus
Focus

Description:

Dynamic Bodies in this simulation.

Type:
Since: 3.0.0
Focus
Focus

Description:

A boundary constraining Bodies.

Type:
Since: 3.0.0
Focus
Focus

Description:

The boundary edges that Bodies can collide with.

Type:
Since: 3.0.0
Focus
Focus

Description:

This simulation's collision processors.

Type:
Since: 3.0.0
Focus
Focus

Description:

The graphics object drawing the debug display.

Type:
Since: 3.0.0
Focus
Focus

Description:

Default debug display settings for new Bodies.

Type:
Since: 3.0.0
Focus
Focus
drawDebug: boolean
Focus
Focus

Description:

Enables the debug display.

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

Description:

Should Physics use a fixed update time-step (true) or sync to the render fps (false)?. False value of this property disables fps and timeScale properties.

Type:
boolean
Default: true
Since: 3.23.0
Focus
Focus
forceX: boolean
Focus
Focus

Description:

Always separate overlapping Bodies horizontally before vertically. False (the default) means Bodies are first separated on the axis of greater gravity, or the vertical axis if neither is greater.

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

Description:

The number of physics steps to be taken per second.

This property is read-only. Use the setFPS method to modify it at run-time.

Type:
number
Default: 60
Since: 3.10.0
Focus
Focus

Description:

Acceleration of Bodies due to gravity, in pixels per second.

Type:
Since: 3.0.0
Focus
Focus
isPaused: boolean
Focus
Focus

Description:

Whether the simulation advances with the game loop.

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

Description:

The maximum number of items per node on the RTree.

This is ignored if useTree is false. If you have a large number of bodies in your world then you may find search performance improves by increasing this value, to allow more items per node and less node division.

Type:
number
Default: 16
Since: 3.0.0
Focus
Focus
scene: Phaser.Scene
Focus
Focus

Description:

The Scene this simulation belongs to.

Type:
Since: 3.0.0
Focus
Focus

Description:

Static Bodies in this simulation.

Type:
Since: 3.0.0
Focus
Focus
staticTree: Phaser.Structs.RTree
Focus
Focus

Description:

The spatial index of Static Bodies.

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

Description:

The number of steps that took place in the last frame.

Type:
number
Since: 3.10.0
Focus
Focus
timeScale: number
Focus
Focus

Description:

Scaling factor applied to the frame rate.

  • 1.0 = normal speed
  • 2.0 = half speed
  • 0.5 = double speed
Type:
number
Default: 1
Since: 3.10.0
Focus
Focus

Description:

The spatial index of Dynamic Bodies.

Type:
Since: 3.0.0
Focus
Focus

Description:

Recycled input for tree searches.

Type:
Since: 3.0.0
Focus
Focus
useTree: boolean
Focus
Focus

Description:

Should this Arcade Physics World use an RTree for Dynamic bodies?

An RTree is a fast way of spatially sorting of all the bodies in the world. However, at certain limits, the cost of clearing and inserting the bodies into the tree every frame becomes more expensive than the search speed gains it provides.

If you have a large number of dynamic bodies in your world then it may be best to disable the use of the RTree by setting this property to false in the physics config.

The number it can cope with depends on browser and device, but a conservative estimate of around 5,000 bodies should be considered the max before disabling it.

This only applies to dynamic bodies. Static bodies are always kept in an RTree, because they don't have to be cleared every frame, so you benefit from the massive search speeds all the time.

Type:
boolean
Default: true
Since: 3.10.0
Focus
Focus

Methods

add(body)
Focus
Focus

Description:

Adds an existing Arcade Physics Body or StaticBody to the simulation.

The body is enabled and added to the local search trees.

Parameters:

name type description
body Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody

The Body to be added to the simulation.

Returns:
Description:

The Body that was added to the simulation.

Since: 3.10.0
Focus
Focus
addCollider(object1, object2, [collideCallback], [processCallback], [callbackContext])
Focus
Focus

Description:

Creates a new Collider object and adds it to the simulation.

A Collider is a way to automatically perform collision checks between two objects, calling the collide and process callbacks if they occur.

Colliders are run as part of the World update, after all of the Bodies have updated.

By creating a Collider you don't need then call World.collide in your update loop, as it will be handled for you automatically.

Parameters:

name type arguments description
object1 Phaser.Types.Physics.Arcade.ArcadeColliderType

The first object to check for collision.

object2 Phaser.Types.Physics.Arcade.ArcadeColliderType

The second object to check for collision.

collideCallback ArcadePhysicsCallback <optional>

The callback to invoke when the two objects collide.

processCallback ArcadePhysicsCallback <optional>

The callback to invoke when the two objects collide. Must return a boolean.

callbackContext * <optional>

The scope in which to call the callbacks.

Returns:
Description:

The Collider that was created.

Since: 3.0.0
Focus
Focus
addListener(event, fn, [context])
Focus
Focus

Description:

Add a listener for a given event.

Parameters:

name type arguments Default description
event string | symbol

The event name.

fn function

The listener function.

context * <optional> this

The context to invoke the listener with.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#addListener
Since: 3.0.0
Focus
Focus
addOverlap(object1, object2, [collideCallback], [processCallback], [callbackContext])
Focus
Focus

Description:

Creates a new Overlap Collider object and adds it to the simulation.

A Collider is a way to automatically perform overlap checks between two objects, calling the collide and process callbacks if they occur.

Colliders are run as part of the World update, after all of the Bodies have updated.

By creating a Collider you don't need then call World.overlap in your update loop, as it will be handled for you automatically.

Parameters:

name type arguments description
object1 Phaser.Types.Physics.Arcade.ArcadeColliderType

The first object to check for overlap.

object2 Phaser.Types.Physics.Arcade.ArcadeColliderType

The second object to check for overlap.

collideCallback ArcadePhysicsCallback <optional>

The callback to invoke when the two objects overlap.

processCallback ArcadePhysicsCallback <optional>

The callback to invoke when the two objects overlap. Must return a boolean.

callbackContext * <optional>

The scope in which to call the callbacks.

Returns:
Description:

The Collider that was created.

Since: 3.0.0
Focus
Focus
circleBodyIntersects(circle, body)
Focus
Focus

Description:

Tests if a circular Body intersects with another Body.

Parameters:

name type description
circle Phaser.Physics.Arcade.Body

The circular body to test.

body Phaser.Physics.Arcade.Body

The rectangular body to test.

Returns:
Description:

True if the two bodies intersect, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
collide(object1, [object2], [collideCallback], [processCallback], [callbackContext])
Focus
Focus

Description:

Performs a collision check and separation between the two physics enabled objects given, which can be single Game Objects, arrays of Game Objects, Physics Groups, arrays of Physics Groups or normal Groups.

If you don't require separation then use Phaser.Physics.Arcade.World#overlap instead.

If two Groups or arrays are passed, each member of one will be tested against each member of the other.

If only one Group is passed (as object1), each member of the Group will be collided against the other members.

If only one Array is passed, the array is iterated and every element in it is tested against the others.

Two callbacks can be provided; they receive the colliding game objects as arguments. If an overlap is detected, the processCallback is called first. It can cancel the collision by returning false. Next the objects are separated and collideCallback is invoked.

Arcade Physics uses the Projection Method of collision resolution and separation. While it's fast and suitable for 'arcade' style games it lacks stability when multiple objects are in close proximity or resting upon each other. The separation that stops two objects penetrating may create a new penetration against a different object. If you require a high level of stability please consider using an alternative physics system, such as Matter.js.

Parameters:

name type arguments description
object1 Phaser.Types.Physics.Arcade.ArcadeColliderType

The first object or array of objects to check.

object2 Phaser.Types.Physics.Arcade.ArcadeColliderType <optional>

The second object or array of objects to check, or undefined.

collideCallback ArcadePhysicsCallback <optional>

An optional callback function that is called if the objects collide.

processCallback ArcadePhysicsCallback <optional>

An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then collideCallback will only be called if this callback returns true.

callbackContext any <optional>

The context in which to run the callbacks.

Returns:
Description:

true if any overlapping Game Objects were separated, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<private> collideGroupVsGroup(group1, group2, [collideCallback], [processCallback], [callbackContext], overlapOnly)
Focus
Focus

Description:

Internal helper for Group vs. Group collisions. Please use Phaser.Physics.Arcade.World#collide instead.

Parameters:

name type arguments description
group1 Phaser.GameObjects.Group

The first object to check for collision.

group2 Phaser.GameObjects.Group

The second object to check for collision.

collideCallback ArcadePhysicsCallback <optional>

An optional callback function that is called if the objects collide.

processCallback ArcadePhysicsCallback <optional>

An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then collideCallback will only be called if this callback returns true.

callbackContext any <optional>

The context in which to run the callbacks.

overlapOnly boolean

Whether this is a collision or overlap check.

Returns:
Description:

True if any objects overlap (with overlapOnly); or true if any overlapping objects were separated.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<private> collideGroupVsTilemapLayer(group, tilemapLayer, collideCallback, processCallback, callbackContext, overlapOnly)
Focus
Focus

Description:

Internal handler for Group vs. Tilemap collisions. Please use Phaser.Physics.Arcade.World#collide instead.

Parameters:

name type description
group Phaser.GameObjects.Group

The first object to check for collision.

tilemapLayer Phaser.Tilemaps.TilemapLayer

The second object to check for collision.

collideCallback ArcadePhysicsCallback

An optional callback function that is called if the objects collide.

processCallback ArcadePhysicsCallback

An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then collideCallback will only be called if this callback returns true.

callbackContext any

The context in which to run the callbacks.

overlapOnly boolean

Whether this is a collision or overlap check.

Returns:
Description:

True if any objects overlap (with overlapOnly); or true if any overlapping objects were separated.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<private> collideHandler(object1, object2, collideCallback, processCallback, callbackContext, overlapOnly)
Focus
Focus

Description:

Internal helper function. Please use Phaser.Physics.Arcade.World#collide and Phaser.Physics.Arcade.World#overlap instead.

Parameters:

name type description
object1 Phaser.Types.Physics.Arcade.ArcadeColliderType

The first object or array of objects to check.

object2 Phaser.Types.Physics.Arcade.ArcadeColliderType

The second object or array of objects to check, or undefined.

collideCallback ArcadePhysicsCallback

An optional callback function that is called if the objects collide.

processCallback ArcadePhysicsCallback

An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then collideCallback will only be called if this callback returns true.

callbackContext any

The context in which to run the callbacks.

overlapOnly boolean

Whether this is a collision or overlap check.

Returns:
Description:

True if any objects overlap (with overlapOnly); or true if any overlapping objects were separated.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<private> collideObjects(object1, [object2], collideCallback, processCallback, callbackContext, overlapOnly)
Focus
Focus

Description:

Internal helper function. Please use Phaser.Physics.Arcade.World#collide instead.

Parameters:

name type arguments description
object1 Phaser.Types.Physics.Arcade.ArcadeColliderType

The first object to check for collision.

object2 Phaser.Types.Physics.Arcade.ArcadeColliderType <optional>

The second object to check for collision.

collideCallback ArcadePhysicsCallback

The callback to invoke when the two objects collide.

processCallback ArcadePhysicsCallback

The callback to invoke when the two objects collide. Must return a boolean.

callbackContext any

The scope in which to call the callbacks.

overlapOnly boolean

Whether this is a collision or overlap check.

Returns:
Description:

True if any objects overlap (with overlapOnly); or true if any overlapping objects were separated.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<private> collideSpriteVsGroup(sprite, group, collideCallback, processCallback, callbackContext, overlapOnly)
Focus
Focus

Description:

Internal handler for Sprite vs. Group collisions. Please use Phaser.Physics.Arcade.World#collide instead.

Parameters:

name type description
sprite Phaser.GameObjects.GameObject

The first object to check for collision.

group Phaser.GameObjects.Group

The second object to check for collision.

collideCallback ArcadePhysicsCallback

The callback to invoke when the two objects collide.

processCallback ArcadePhysicsCallback

The callback to invoke when the two objects collide. Must return a boolean.

callbackContext any

The scope in which to call the callbacks.

overlapOnly boolean

Whether this is a collision or overlap check.

Returns:
Description:

true if the Sprite collided with the given Group, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<private> collideSpriteVsSprite(sprite1, sprite2, [collideCallback], [processCallback], [callbackContext], overlapOnly)
Focus
Focus

Description:

Internal handler for Sprite vs. Sprite collisions. Please use Phaser.Physics.Arcade.World#collide instead.

Parameters:

name type arguments description
sprite1 Phaser.GameObjects.GameObject

The first object to check for collision.

sprite2 Phaser.GameObjects.GameObject

The second object to check for collision.

collideCallback ArcadePhysicsCallback <optional>

An optional callback function that is called if the objects collide.

processCallback ArcadePhysicsCallback <optional>

An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then collideCallback will only be called if this callback returns true.

callbackContext any <optional>

The context in which to run the callbacks.

overlapOnly boolean

Whether this is a collision or overlap check.

Returns:
Description:

True if any objects overlap (with overlapOnly); or true if any overlapping objects were separated.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
collideSpriteVsTilemapLayer(sprite, tilemapLayer, [collideCallback], [processCallback], [callbackContext], [overlapOnly])
Focus
Focus

Description:

Internal handler for Sprite vs. Tilemap collisions. Please use Phaser.Physics.Arcade.World#collide instead.

Parameters:

name type arguments description
sprite Phaser.GameObjects.GameObject

The first object to check for collision.

tilemapLayer Phaser.Tilemaps.TilemapLayer

The second object to check for collision.

collideCallback ArcadePhysicsCallback <optional>

An optional callback function that is called if the objects collide.

processCallback ArcadePhysicsCallback <optional>

An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then collideCallback will only be called if this callback returns true.

callbackContext any <optional>

The context in which to run the callbacks.

overlapOnly boolean <optional>

Whether this is a collision or overlap check.

Returns:
Description:

True if any objects overlap (with overlapOnly); or true if any overlapping objects were separated.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<private> collideSpriteVsTilesHandler(sprite, tilemapLayer, [collideCallback], [processCallback], [callbackContext], [overlapOnly], [isLayer])
Focus
Focus

Description:

Internal handler for Sprite vs. Tilemap collisions. Please use Phaser.Physics.Arcade.World#collide instead.

Parameters:

name type arguments description
sprite Phaser.GameObjects.GameObject

The first object to check for collision.

tilemapLayer Phaser.Tilemaps.TilemapLayer

The second object to check for collision.

collideCallback ArcadePhysicsCallback <optional>

An optional callback function that is called if the objects collide.

processCallback ArcadePhysicsCallback <optional>

An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then collideCallback will only be called if this callback returns true.

callbackContext any <optional>

The context in which to run the callbacks.

overlapOnly boolean <optional>

Whether this is a collision or overlap check.

isLayer boolean <optional>

Is this check coming from a TilemapLayer or an array of tiles?

Returns:
Description:

True if any objects overlap (with overlapOnly); or true if any overlapping objects were separated.

Type:
  • boolean
Since: 3.17.0
Focus
Focus
collideTiles(sprite, tiles, [collideCallback], [processCallback], [callbackContext])
Focus
Focus

Description:

This advanced method is specifically for testing for collision between a single Sprite and an array of Tile objects.

You should generally use the collide method instead, with a Sprite vs. a Tilemap Layer, as that will perform tile filtering and culling for you, as well as handle the interesting face collision automatically.

This method is offered for those who would like to check for collision with specific Tiles in a layer, without having to set any collision attributes on the tiles in question. This allows you to perform quick dynamic collisions on small sets of Tiles. As such, no culling or checks are made to the array of Tiles given to this method, you should filter them before passing them to this method.

Important: Use of this method skips the interesting faces system that Tilemap Layers use. This means if you have say a row or column of tiles, and you jump into, or walk over them, it's possible to get stuck on the edges of the tiles as the interesting face calculations are skipped. However, for quick-fire small collision set tests on dynamic maps, this method can prove very useful.

Parameters:

name type arguments description
sprite Phaser.GameObjects.GameObject

The first object to check for collision.

tiles Array.<Phaser.Tilemaps.Tile>

An array of Tiles to check for collision against.

collideCallback ArcadePhysicsCallback <optional>

An optional callback function that is called if the objects collide.

processCallback ArcadePhysicsCallback <optional>

An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then collideCallback will only be called if this callback returns true.

callbackContext any <optional>

The context in which to run the callbacks.

Returns:
Description:

True if any objects overlap (with overlapOnly); or true if any overlapping objects were separated.

Type:
  • boolean
Since: 3.17.0
Focus
Focus
computeAngularVelocity(body, delta)
Focus
Focus

Description:

Calculates a Body's angular velocity.

Parameters:

name type description
body Phaser.Physics.Arcade.Body

The Body to compute the velocity for.

delta number

The delta value to be used in the calculation, in seconds.

Since: 3.10.0
Focus
Focus
computeVelocity(body, delta)
Focus
Focus

Description:

Calculates a Body's per-axis velocity.

Parameters:

name type description
body Phaser.Physics.Arcade.Body

The Body to compute the velocity for.

delta number

The delta value to be used in the calculation, in seconds.

Since: 3.0.0
Focus
Focus
createDebugGraphic()
Focus
Focus

Description:

Creates a Graphics Game Object that the world will use to render the debug display to.

This is called automatically when the World is instantiated if the debug config property was set to true. However, you can call it at any point should you need to display the debug Graphic from a fixed point.

You can control which objects are drawn to the Graphics object, and the colors they use, by setting the debug properties in the physics config.

You should not typically use this in a production game. Use it to aid during debugging.

Returns:
Description:

The Graphics object that was created for use by the World.

Since: 3.0.0
Focus
Focus
destroy()
Focus
Focus

Description:

Shuts down the simulation and disconnects it from the current scene.

Overrides: Phaser.Events.EventEmitter#destroy
Since: 3.0.0
Focus
Focus
disable(object)
Focus
Focus

Description:

Disables the Arcade Physics Body of a Game Object, an array of Game Objects, or the children of a Group.

The difference between this and the disableBody method is that you can pass arrays or Groups to this method.

The body itself is not deleted, it just has its enable property set to false, which means you can re-enable it again at any point by passing it to enable World.enable or World.add.

Parameters:

name type description
object Phaser.GameObjects.GameObject | Array.<Phaser.GameObjects.GameObject> | Phaser.GameObjects.Group | Array.<Phaser.GameObjects.Group>

The object, or objects, on which to disable the bodies.

Since: 3.0.0
Focus
Focus
disableBody(body)
Focus
Focus

Description:

Disables an existing Arcade Physics Body or StaticBody and removes it from the simulation.

The body is disabled and removed from the local search trees.

The body itself is not deleted, it just has its enable property set to false, which means you can re-enable it again at any point by passing it to enable World.enable or World.add.

Parameters:

name type description
body Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody

The Body to be disabled.

Since: 3.0.0
Focus
Focus
emit(event, [args])
Focus
Focus

Description:

Calls each of the listeners registered for a given event.

Parameters:

name type arguments description
event string | symbol

The event name.

args * <optional>

Additional arguments that will be passed to the event handler.

Returns:
Description:

true if the event had listeners, else false.

Type:
  • boolean
Inherited from: Phaser.Events.EventEmitter#emit
Since: 3.0.0
Focus
Focus
enable(object, [bodyType])
Focus
Focus

Description:

Adds an Arcade Physics Body to a Game Object, an array of Game Objects, or the children of a Group.

The difference between this and the enableBody method is that you can pass arrays or Groups to this method.

You can specify if the bodies are to be Dynamic or Static. A dynamic body can move via velocity and acceleration. A static body remains fixed in place and as such is able to use an optimized search tree, making it ideal for static elements such as level objects. You can still collide and overlap with static bodies.

Normally, rather than calling this method directly, you'd use the helper methods available in the Arcade Physics Factory, such as:

this.physics.add.image(x, y, textureKey);
this.physics.add.sprite(x, y, textureKey);

Calling factory methods encapsulates the creation of a Game Object and the creation of its body at the same time. If you are creating custom classes then you can pass them to this method to have their bodies created.

Parameters:

name type arguments description
object Phaser.GameObjects.GameObject | Array.<Phaser.GameObjects.GameObject> | Phaser.GameObjects.Group | Array.<Phaser.GameObjects.Group>

The object, or objects, on which to create the bodies.

bodyType number <optional>

The type of Body to create. Either DYNAMIC_BODY or STATIC_BODY.

Since: 3.0.0
Focus
Focus
enableBody(object, [bodyType])
Focus
Focus

Description:

Creates an Arcade Physics Body on a single Game Object.

If the Game Object already has a body, this method will simply add it back into the simulation.

You can specify if the body is Dynamic or Static. A dynamic body can move via velocity and acceleration. A static body remains fixed in place and as such is able to use an optimized search tree, making it ideal for static elements such as level objects. You can still collide and overlap with static bodies.

Normally, rather than calling this method directly, you'd use the helper methods available in the Arcade Physics Factory, such as:

this.physics.add.image(x, y, textureKey);
this.physics.add.sprite(x, y, textureKey);

Calling factory methods encapsulates the creation of a Game Object and the creation of its body at the same time. If you are creating custom classes then you can pass them to this method to have their bodies created.

Parameters:

name type arguments description
object Phaser.GameObjects.GameObject

The Game Object on which to create the body.

bodyType number <optional>

The type of Body to create. Either DYNAMIC_BODY or STATIC_BODY.

Returns:
Description:

The Game Object on which the body was created.

Since: 3.0.0
Focus
Focus
eventNames()
Focus
Focus

Description:

Return an array listing the events for which the emitter has registered listeners.

Type:
  • Array.<(string
  • symbol)>
Inherited from: Phaser.Events.EventEmitter#eventNames
Since: 3.0.0
Focus
Focus
intersects(body1, body2)
Focus
Focus

Description:

Checks to see if two Bodies intersect at all.

Parameters:

name type description
body1 Phaser.Physics.Arcade.Body

The first body to check.

body2 Phaser.Physics.Arcade.Body

The second body to check.

Returns:
Description:

True if the two bodies intersect, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
listenerCount(event)
Focus
Focus

Description:

Return the number of listeners listening to a given event.

Parameters:

name type description
event string | symbol

The event name.

Returns:
Description:

The number of listeners.

Type:
  • number
Inherited from: Phaser.Events.EventEmitter#listenerCount
Since: 3.0.0
Focus
Focus
listeners(event)
Focus
Focus

Description:

Return the listeners registered for a given event.

Parameters:

name type description
event string | symbol

The event name.

Returns:
Description:

The registered listeners.

Type:
  • Array.<function()>
Inherited from: Phaser.Events.EventEmitter#listeners
Since: 3.0.0
Focus
Focus
off(event, [fn], [context], [once])
Focus
Focus

Description:

Remove the listeners of a given event.

Parameters:

name type arguments description
event string | symbol

The event name.

fn function <optional>

Only remove the listeners that match this function.

context * <optional>

Only remove the listeners that have this context.

once boolean <optional>

Only remove one-time listeners.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#off
Since: 3.0.0
Focus
Focus
on(event, fn, [context])
Focus
Focus

Description:

Add a listener for a given event.

Parameters:

name type arguments Default description
event string | symbol

The event name.

fn function

The listener function.

context * <optional> this

The context to invoke the listener with.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#on
Since: 3.0.0
Focus
Focus
once(event, fn, [context])
Focus
Focus

Description:

Add a one-time listener for a given event.

Parameters:

name type arguments Default description
event string | symbol

The event name.

fn function

The listener function.

context * <optional> this

The context to invoke the listener with.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#once
Since: 3.0.0
Focus
Focus
overlap(object1, [object2], [overlapCallback], [processCallback], [callbackContext])
Focus
Focus

Description:

Tests if Game Objects overlap.

See details in Phaser.Physics.Arcade.World#collide.

Parameters:

name type arguments description
object1 Phaser.Types.Physics.Arcade.ArcadeColliderType

The first object or array of objects to check.

object2 Phaser.Types.Physics.Arcade.ArcadeColliderType <optional>

The second object or array of objects to check, or undefined.

overlapCallback ArcadePhysicsCallback <optional>

An optional callback function that is called if the objects overlap.

processCallback ArcadePhysicsCallback <optional>

An optional callback function that lets you perform additional checks against the two objects if they overlap. If this is set then overlapCallback will only be called if this callback returns true.

callbackContext * <optional>

The context in which to run the callbacks.

Returns:
Description:

True if at least one Game Object overlaps another.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
overlapTiles(sprite, tiles, [collideCallback], [processCallback], [callbackContext])
Focus
Focus

Description:

This advanced method is specifically for testing for overlaps between a single Sprite and an array of Tile objects.

You should generally use the overlap method instead, with a Sprite vs. a Tilemap Layer, as that will perform tile filtering and culling for you, as well as handle the interesting face collision automatically.

This method is offered for those who would like to check for overlaps with specific Tiles in a layer, without having to set any collision attributes on the tiles in question. This allows you to perform quick dynamic overlap tests on small sets of Tiles. As such, no culling or checks are made to the array of Tiles given to this method, you should filter them before passing them to this method.

Parameters:

name type arguments description
sprite Phaser.GameObjects.GameObject

The first object to check for collision.

tiles Array.<Phaser.Tilemaps.Tile>

An array of Tiles to check for collision against.

collideCallback ArcadePhysicsCallback <optional>

An optional callback function that is called if the objects overlap.

processCallback ArcadePhysicsCallback <optional>

An optional callback function that lets you perform additional checks against the two objects if they collide. If this is set then collideCallback will only be called if this callback returns true.

callbackContext any <optional>

The context in which to run the callbacks.

Returns:
Description:

True if any objects overlap (with overlapOnly); or true if any overlapping objects were separated.

Type:
  • boolean
Since: 3.17.0
Focus
Focus
pause()
Focus
Focus

Description:

Pauses the simulation.

A paused simulation does not update any existing bodies, or run any Colliders.

However, you can still enable and disable bodies within it, or manually run collide or overlap checks.

Returns:
Description:

This World object.

Since: 3.0.0
Focus
Focus
postUpdate()
Focus
Focus

Description:

Updates bodies, draws the debug display, and handles pending queue operations.

Since: 3.0.0
Focus
Focus
remove(body)
Focus
Focus

Description:

Removes an existing Arcade Physics Body or StaticBody from the simulation.

The body is disabled and removed from the local search trees.

The body itself is not deleted, it just has its enabled property set to false, which means you can re-enable it again at any point by passing it to enable enable or add.

Parameters:

name type description
body Phaser.Physics.Arcade.Body | Phaser.Physics.Arcade.StaticBody

The body to be removed from the simulation.

Since: 3.0.0
Focus
Focus
removeAllListeners([event])
Focus
Focus

Description:

Remove all listeners, or those of the specified event.

Parameters:

name type arguments description
event string | symbol <optional>

The event name.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#removeAllListeners
Since: 3.0.0
Focus
Focus
removeCollider(collider)
Focus
Focus

Description:

Removes a Collider from the simulation so it is no longer processed.

This method does not destroy the Collider. If you wish to add it back at a later stage you can call World.colliders.add(Collider).

If you no longer need the Collider you can call the Collider.destroy method instead, which will automatically clear all of its references and then remove it from the World. If you call destroy on a Collider you don't need to pass it to this method too.

Parameters:

name type description
collider Phaser.Physics.Arcade.Collider

The Collider to remove from the simulation.

Returns:
Description:

This World object.

Since: 3.0.0
Focus
Focus
removeListener(event, [fn], [context], [once])
Focus
Focus

Description:

Remove the listeners of a given event.

Parameters:

name type arguments description
event string | symbol

The event name.

fn function <optional>

Only remove the listeners that match this function.

context * <optional>

Only remove the listeners that have this context.

once boolean <optional>

Only remove one-time listeners.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#removeListener
Since: 3.0.0
Focus
Focus
resume()
Focus
Focus

Description:

Resumes the simulation, if paused.

Returns:
Description:

This World object.

Since: 3.0.0
Focus
Focus
separate(body1, body2, [processCallback], [callbackContext], [overlapOnly], [intersects])
Focus
Focus

Description:

Separates two Bodies.

Parameters:

name type arguments description
body1 Phaser.Physics.Arcade.Body

The first Body to be separated.

body2 Phaser.Physics.Arcade.Body

The second Body to be separated.

processCallback ArcadePhysicsCallback <optional>

The process callback.

callbackContext * <optional>

The context in which to invoke the callback.

overlapOnly boolean <optional>

If this a collide or overlap check?

intersects boolean <optional>

Assert that the bodies intersect and should not be tested before separation.

Returns:
Description:

True if separation occurred, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
separateCircle(body1, body2, [overlapOnly], [bias])
Focus
Focus

Description:

Separates two Bodies, when both are circular.

Parameters:

name type arguments description
body1 Phaser.Physics.Arcade.Body

The first Body to be separated.

body2 Phaser.Physics.Arcade.Body

The second Body to be separated.

overlapOnly boolean <optional>

If this a collide or overlap check?

bias number <optional>

A small value added to the calculations.

Returns:
Description:

True if separation occurred, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
setBounds(x, y, width, height, [checkLeft], [checkRight], [checkUp], [checkDown])
Focus
Focus

Description:

Sets the position, size and properties of the World boundary.

The World boundary is an invisible rectangle that defines the edges of the World. If a Body is set to collide with the world bounds then it will automatically stop when it reaches any of the edges. You can optionally set which edges of the boundary should be checked against.

Parameters:

name type arguments description
x number

The top-left x coordinate of the boundary.

y number

The top-left y coordinate of the boundary.

width number

The width of the boundary.

height number

The height of the boundary.

checkLeft boolean <optional>

Should bodies check against the left edge of the boundary?

checkRight boolean <optional>

Should bodies check against the right edge of the boundary?

checkUp boolean <optional>

Should bodies check against the top edge of the boundary?

checkDown boolean <optional>

Should bodies check against the bottom edge of the boundary?

Returns:
Description:

This World object.

Since: 3.0.0
Focus
Focus
setBoundsCollision([left], [right], [up], [down])
Focus
Focus

Description:

Enables or disables collisions on each edge of the World boundary.

Parameters:

name type arguments Default description
left boolean <optional> true

Should bodies check against the left edge of the boundary?

right boolean <optional> true

Should bodies check against the right edge of the boundary?

up boolean <optional> true

Should bodies check against the top edge of the boundary?

down boolean <optional> true

Should bodies check against the bottom edge of the boundary?

Returns:
Description:

This World object.

Since: 3.0.0
Focus
Focus
setFPS(framerate)
Focus
Focus

Description:

Sets the frame rate to run the simulation at.

The frame rate value is used to simulate a fixed update time step. This fixed time step allows for a straightforward implementation of a deterministic game state.

This frame rate is independent of the frequency at which the game is rendering. The higher you set the fps, the more physics simulation steps will occur per game step. Conversely, the lower you set it, the less will take place.

You can optionally advance the simulation directly yourself by calling the step method.

Parameters:

name type description
framerate number

The frame rate to advance the simulation at.

Returns:
Description:

This World object.

Since: 3.10.0
Focus
Focus
shutdown()
Focus
Focus

Description:

Shuts down the simulation, clearing physics data and removing listeners.

Overrides: Phaser.Events.EventEmitter#shutdown
Since: 3.0.0
Focus
Focus
step(delta)
Focus
Focus

Description:

Advances the simulation by a time increment.

Parameters:

name type description
delta number

The delta time amount, in seconds, by which to advance the simulation.

Since: 3.10.0
Focus
Focus
update(time, delta)
Focus
Focus

Description:

Advances the simulation based on the elapsed time and fps rate.

This is called automatically by your Scene and does not need to be invoked directly.

Parameters:

name type description
time number

The current timestamp as generated by the Request Animation Frame or SetTimeout.

delta number

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

Since: 3.0.0
Focus
Focus
updateMotion(body, delta)
Focus
Focus

Description:

Calculates a Body's velocity and updates its position.

Parameters:

name type description
body Phaser.Physics.Arcade.Body

The Body to be updated.

delta number

The delta value to be used in the motion calculations, in seconds.

Since: 3.0.0
Focus
Focus
wrap(object, [padding])
Focus
Focus

Description:

Wrap an object's coordinates (or several objects' coordinates) within Phaser.Physics.Arcade.World#bounds.

If the object is outside any boundary edge (left, top, right, bottom), it will be moved to the same offset from the opposite edge (the interior).

Parameters:

name type arguments description
object any

A Game Object, a Group, an object with x and y coordinates, or an array of such objects.

padding number <optional>

An amount added to each boundary edge during the operation.

Since: 3.3.0
Focus
Focus
wrapArray(objects, [padding])
Focus
Focus

Description:

Wrap each object's coordinates within Phaser.Physics.Arcade.World#bounds.

Parameters:

name type arguments description
objects Array.<*>

An array of objects to be wrapped.

padding number <optional>

An amount added to the boundary.

Since: 3.3.0
Focus
Focus
wrapObject(object, [padding])
Focus
Focus

Description:

Wrap an object's coordinates within Phaser.Physics.Arcade.World#bounds.

Parameters:

name type arguments description
object *

A Game Object, a Physics Body, or any object with x and y coordinates

padding number <optional>

An amount added to the boundary.

Since: 3.3.0
Focus
Focus