Shaku

Shaku JS

Back To Table of Content

Tilemap

TilemapShape

Collision tilemap class. A collision tilemap shape is a grid of equal-sized cells that can either block or not (+ have collision flags). Its the most efficient (both memory and CPU) way to implement grid based / tilemap collision.

Kind: global class

new TilemapShape(offset, gridSize, tileSize, borderThickness)

Create the collision tilemap.

Param Type Description
offset Vector2 Tilemap top-left corner.
gridSize Vector2 Number of tiles on X and Y axis.
tileSize Vector2 The size of a single tile.
borderThickness Number Set a border collider with this thickness.

tilemapShape.shapeId

Kind: instance property of TilemapShape

tilemapShape.setTile(index, haveCollision, collisionFlags)

Set the state of a tile.

Kind: instance method of TilemapShape

Param Type Description
index Vector2 Tile index.
haveCollision Boolean Does this tile have collision?
collisionFlags Number Optional collision flag to set for this tile.

tilemapShape.getTileAt(position) ⇒ RectangleShape

Get the collision shape of a tile at a given position.

Kind: instance method of TilemapShape
Returns: RectangleShape - Collision shape at this position, or null if not set.

Param Type Description
position Vector2 Position to get tile at.

tilemapShape.iterateTilesAtRegion(region, callback)

Iterate all tiles in given region, represented by a rectangle.

Kind: instance method of TilemapShape

Param Type Description
region Rectangle Rectangle to get tiles for.
callback function Method to invoke for every tile. Return false to break iteration.

tilemapShape.getTilesAtRegion(region) ⇒ Array.<RectangleShape>

Get all tiles in given region, represented by a rectangle.

Kind: instance method of TilemapShape
Returns: Array.<RectangleShape> - Array with rectangle shapes or empty if none found.

Param Type Description
region Rectangle Rectangle to get tiles for.

tilemapShape._getRadius()

Kind: instance method of TilemapShape

tilemapShape._getBoundingBox()

Kind: instance method of TilemapShape

tilemapShape.getCenter()

Kind: instance method of TilemapShape

tilemapShape.debugDraw()

Kind: instance method of TilemapShape