Class: TileBody

Phaser.Physics.Matter. TileBody

A wrapper around a Tile that provides access to a corresponding Matter body. A tile can only
have one Matter body associated with it. You can either pass in an existing Matter body for
the tile or allow the constructor to create the corresponding body for you. If the Tile has a
collision group (defined in Tiled), those shapes will be used to create the body. If not, the
tile's rectangle bounding box will be used.

The corresponding body will be accessible on the Tile itself via Tile.physics.matterBody.

Note: not all Tiled collision shapes are supported. See
Phaser.Physics.Matter.TileBody#setFromTileCollision for more information.


new TileBody(world, tile [, options])

Parameters:
Name Type Argument Description
world Phaser.Physics.Matter.World

[description]

tile Phaser.Tilemaps.Tile

The target tile that should have a Matter body.

options object <optional>

Options to be used when creating the Matter body. See
Phaser.Physics.Matter.Matter.Body for a list of what Matter accepts.

Properties
Name Type Argument Default Description
body Phaser.Physics.Matter.Matter.Body <optional>
null

An existing Matter body to
be used instead of creating a new one.

isStatic boolean <optional>
true

Whether or not the newly created body should be
made static. This defaults to true since typically tiles should not be moved.

addToWorld boolean <optional>
true

Whether or not to add the newly created body (or
existing body if options.body is used) to the Matter world.

Since: 3.0.0
Source: src/physics/matter-js/MatterTileBody.js (Line 15)

Extends

Members


<readonly> centerOfMass

The body's center of mass.

Since: 3.10.0
Inherited From:
Source: src/physics/matter-js/components/Mass.js (Line 52)

tile :Phaser.Tilemaps.Tile

The tile object the body is associated with.

Type:
Since: 3.0.0
Source: src/physics/matter-js/MatterTileBody.js (Line 70)

world :Phaser.Physics.Matter.World

The Matter world the body exists within.

Type:
Since: 3.0.0
Source: src/physics/matter-js/MatterTileBody.js (Line 79)

Methods


destroy()

Removes the current body from the tile and the world.

Since: 3.0.0
Source: src/physics/matter-js/MatterTileBody.js (Line 304)
Returns:

This TileBody object.

Type
Phaser.Physics.Matter.TileBody

isSensor()

[description]

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Sensor.js (Line 32)
Returns:

[description]

Type
boolean

isStatic()

[description]

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Static.js (Line 34)
Returns:

[description]

Type
boolean

removeBody()

Removes the current body from the TileBody and from the Matter world

Since: 3.0.0
Source: src/physics/matter-js/MatterTileBody.js (Line 284)
Returns:

This TileBody object.

Type
Phaser.Physics.Matter.TileBody

setBody(body [, addToWorld])

Sets the current body to the given body. This will remove the previous body, if one already
exists.

Parameters:
Name Type Argument Default Description
body MatterJS.Body

The new Matter body to use.

addToWorld boolean <optional>
true

Whether or not to add the body to the Matter world.

Since: 3.0.0
Source: src/physics/matter-js/MatterTileBody.js (Line 252)
Returns:

This TileBody object.

Type
Phaser.Physics.Matter.TileBody

setBounce(value)

[description]

Parameters:
Name Type Description
value number

[description]

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Bounce.js (Line 15)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setCollidesWith(categories)

[description]

Parameters:
Name Type Description
categories number | Array.<number>

A unique category bitfield, or an array of them.

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Collision.js (Line 49)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setCollisionCategory(value)

[description]

Parameters:
Name Type Description
value number

Unique category bitfield.

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Collision.js (Line 15)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setCollisionGroup(value)

[description]

Parameters:
Name Type Description
value number

Unique group index.

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Collision.js (Line 32)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setDensity(value)

[description]

Parameters:
Name Type Description
value number

[description]

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Mass.js (Line 35)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setFriction(value [, air] [, fstatic])

[description]

Parameters:
Name Type Argument Description
value number

[description]

air number <optional>

[description]

fstatic number <optional>

[description]

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Friction.js (Line 15)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setFrictionAir(value)

[description]

Parameters:
Name Type Description
value number

[description]

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Friction.js (Line 44)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setFrictionStatic(value)

[description]

Parameters:
Name Type Description
value number

[description]

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Friction.js (Line 61)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setFromTileCollision( [options])

Sets the current body from the collision group associated with the Tile. This is typically
set up in Tiled's collision editor.

Note: Matter doesn't support all shapes from Tiled. Rectangles and polygons are directly
supported. Ellipses are converted into circle bodies. Polylines are treated as if they are
closed polygons. If a tile has multiple shapes, a multi-part body will be created. Concave
shapes are supported if poly-decomp library is included. Decomposition is not guaranteed to
work for complex shapes (e.g. holes), so it's often best to manually decompose a concave
polygon into multiple convex polygons yourself.

Parameters:
Name Type Argument Description
options object <optional>

Options to be used when creating the Matter body. See MatterJS.Body for a list of what Matter accepts.

Properties
Name Type Argument Default Description
isStatic boolean <optional>
true

Whether or not the newly created body should be
made static. This defaults to true since typically tiles should not be moved.

addToWorld boolean <optional>
true

Whether or not to add the newly created body (or
existing body if options.body is used) to the Matter world.

Since: 3.0.0
Source: src/physics/matter-js/MatterTileBody.js (Line 153)
Returns:

This TileBody object.

Type
Phaser.Physics.Matter.TileBody

setFromTileRectangle( [options])

Sets the current body to a rectangle that matches the bounds of the tile.

Parameters:
Name Type Argument Description
options object <optional>

Options to be used when creating the Matter body. See MatterJS.Body for a list of what Matter accepts.

Properties
Name Type Argument Default Description
isStatic boolean <optional>
true

Whether or not the newly created body should be
made static. This defaults to true since typically tiles should not be moved.

addToWorld boolean <optional>
true

Whether or not to add the newly created body (or
existing body if options.body is used) to the Matter world.

Since: 3.0.0
Source: src/physics/matter-js/MatterTileBody.js (Line 123)
Returns:

This TileBody object.

Type
Phaser.Physics.Matter.TileBody

setIgnoreGravity(value)

A togglable function for ignoring world gravity in real-time on the current body.

Parameters:
Name Type Description
value boolean

Set to true to ignore the effect of world gravity, or false to not ignore it.

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Gravity.js (Line 15)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setMass(value)

[description]

Parameters:
Name Type Description
value number

[description]

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Mass.js (Line 18)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setSensor(value)

[description]

Parameters:
Name Type Description
value boolean

[description]

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Sensor.js (Line 15)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setSleepEndEvent(value)

[description]

Parameters:
Name Type Description
value boolean

[description]

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Sleep.js (Line 84)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setSleepEvents(start, end)

[description]

Parameters:
Name Type Description
start boolean

[description]

end boolean

[description]

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Sleep.js (Line 36)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setSleepStartEvent(value)

[description]

Parameters:
Name Type Description
value boolean

[description]

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Sleep.js (Line 55)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setSleepThreshold( [value])

[description]

Parameters:
Name Type Argument Default Description
value number <optional>
60

[description]

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Sleep.js (Line 17)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject

setStatic(value)

[description]

Parameters:
Name Type Description
value boolean

[description]

Since: 3.0.0
Inherited From:
Source: src/physics/matter-js/components/Static.js (Line 17)
Returns:

This Game Object.

Type
Phaser.GameObjects.GameObject