CollisionTiles

platypus.components. CollisionTiles

new CollisionTiles()

This component causes the tile-map to collide with other entities. It must be part of a collision group and will cause "hit-by-tile" messages to fire on colliding entities.

Source:
Listens to Events:

Methods

getAABB() → {platypus.AABB}

Returns the axis-aligned bounding box of the entire map.

Source:
Returns:
Type:
platypus.AABB

aabb The returned object provides the top, left, width, and height of the collision map.

getCollisionMatrix(originX, originY, width, height) → {Array}

Gets a subset of the collision tile grid as a 2D array.

Source:
Parameters:
Name Type Description
originX number

Grid coordinate for the left side of the bounding box.

originY number

Grid coordinate for the top of the bounding box.

width number

Cell width of the bounding box.

height number

Cell height of the bounding box.

Returns:
Type:
Array

getTileShapes(aabb, prevAABB, collisionTypeopt) → {Array}

Returns all the collision tiles within the provided axis-aligned bounding box as an array of shapes.

Source:
Parameters:
Name Type Attributes Description
aabb platypus.AABB

The axis-aligned bounding box for which tiles should be returned.

prevAABB platypus.AABB

The axis-aligned bounding box for a previous location to test for jump-through tiles.

collisionType String <optional>

The type of collision to check for. If not specified, "tiles" is used. (Since 0.8.3)

Returns:
Type:
Array

Each returned object provides the CollisionShape of a tile.

isTile(x, y) → {boolean}

Confirms whether a particular map grid coordinate contains a tile.

Source:
Parameters:
Name Type Description
x number

Integer specifying the column of tiles in the collision map to check.

y number

Integer specifying the row of tiles in the collision map to check.

Returns:
Type:
boolean

Returns true if the coordinate contains a collision tile, false if it does not.

setCollisionMatrix(sourceArray, originX, originY, width, height)

Sets a subset of the collision tile grid.

Source:
Parameters:
Name Type Description
sourceArray Array

A 2D array describing the collision tiles to insert into the collision tile grid.

originX number

Grid coordinate for the left side of the bounding box.

originY number

Grid coordinate for the top of the bounding box.

width number

Cell width of the bounding box.

height number

Cell height of the bounding box.

transform(transformopt)

Performs a transform of a subset of the collision tile grid.

Source:
Parameters:
Name Type Attributes Description
transform Object <optional>

A list of key/value pairs describing the transform.

Name Type Attributes Default Description
type String <optional>
"horizontal"

The type of transform; one of the following: "horizontal", "vertical", "diagonal", "diagonal-inverse", "rotate-90", "rotate-180", "rotate-270". Height and width should match for diagonal flips and 90 degree rotations.

left number <optional>
0

Grid coordinate for the left side of the bounding box.

top number <optional>
0

Grid coordinate for the top of the bounding box.

width number <optional>
grid.width

Cell width of the bounding box.

height number <optional>
grid.height

Cell height of the bounding box.

translate(translateopt)

Performs a translation of a subset of the collision tile grid.

Source:
Parameters:
Name Type Attributes Description
translate Object <optional>

A list of key/value pairs describing the translation.

Name Type Attributes Default Description
dx number <optional>
0

Movement in columns.

dy number <optional>
0

Movement in rows.

left number <optional>
0

Grid coordinate for the left side of the bounding box.

top number <optional>
0

Grid coordinate for the top of the bounding box.

width number <optional>
grid.width

Cell width of the bounding box.

height number <optional>
grid.height

Cell height of the bounding box.