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 MatterTileOptions <optional>

Options to be used when creating the Matter body.

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

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

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

Methods


destroy()

Removes the current body from the tile and the world.

Since: 3.0.0
Source: src/physics/matter-js/MatterTileBody.js (Line 306)
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 286)
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 254)
Returns:

This TileBody object.

Type
Phaser.Physics.Matter.TileBody

setBounce(value)

Sets the restitution on the physics object.

Parameters:
Name Type Description
value number

A Number that defines the restitution (elasticity) of the body. The value is always positive and is in the range (0, 1). A value of 0 means collisions may be perfectly inelastic and no bouncing may occur. A value of 0.8 means the body may bounce back with approximately 80% of its kinetic energy. Note that collision response is based on pairs of bodies, and that restitution values are combined with the following formula: Math.max(bodyA.restitution, bodyB.restitution)

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)

Sets the collision mask for this Game Object's Matter Body. Two Matter Bodies with different collision groups will only collide if each one includes the other's category in its mask based on a bitwise AND, i.e. (categoryA & maskB) !== 0 and (categoryB & maskA) !== 0 are both true.

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)

Sets the collision category of this Game Object's Matter Body. This number must be a power of two between 2^0 (= 1) and 2^31. Two bodies with different collision groups (see #setCollisionGroup) will only collide if their collision categories are included in their collision masks (see #setCollidesWith).

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)

Sets the collision group of this Game Object's Matter Body. If this is zero or two Matter Bodies have different values, they will collide according to the usual rules (see #setCollisionCategory and #setCollisionGroup). If two Matter Bodies have the same positive value, they will always collide; if they have the same negative value, they will never collide.

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)

Sets density of the body.

Parameters:
Name Type Description
value number

The new density of the body.

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

Sets new friction values for this Game Object's Matter Body.

Parameters:
Name Type Argument Description
value number

The new friction of the body, between 0 and 1, where 0 allows the Body to slide indefinitely, while 1 allows it to stop almost immediately after a force is applied.

air number <optional>

If provided, the new air resistance of the Body. The higher the value, the faster the Body will slow as it moves through space. 0 means the body has no air resistance.

fstatic number <optional>

If provided, the new static friction of the Body. The higher the value (e.g. 10), the more force it will take to initially get the Body moving when it is nearly stationary. 0 means the body will never "stick" when it is nearly stationary.

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)

Sets a new air resistance for this Game Object's Matter Body. A value of 0 means the Body will never slow as it moves through space. The higher the value, the faster a Body slows when moving through space.

Parameters:
Name Type Description
value number

The new air resistance for the Body.

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)

Sets a new static friction for this Game Object's Matter Body. A value of 0 means the Body will never "stick" when it is nearly stationary. The higher the value (e.g. 10), the more force it will take to initially get the Body moving when it is nearly stationary.

Parameters:
Name Type Description
value number

The new static friction for the Body.

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 MatterBodyTileOptions <optional>

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

Since: 3.0.0
Source: src/physics/matter-js/MatterTileBody.js (Line 157)
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 MatterBodyTileOptions <optional>

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

Since: 3.0.0
Source: src/physics/matter-js/MatterTileBody.js (Line 131)
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)

Sets the mass of the Game Object's Matter Body.

Parameters:
Name Type Description
value number

The new mass of the body.

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 85)
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 37)
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 56)
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 18)
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