ig.

utilstile

Static utilities for working with tiles and collision maps.
- shapes are extracted by ig.GameExtended#loadLevel, but the work is done by ig.utilstile.shapesFromCollisionMap Tip: Impact++ can automatically convert collision maps into shapes (vertices, edges, etc).

Author:
  • Collin Hover - collinhover.com
Source:

<static, readonly> defaultTileSegmentsDef :Object

Definitions of tile types as segments so we don't have to recalculate each tile.

Source:

<static, readonly> defaultTileVerticesDef :Object

Definitions of tile types as vertices so we don't have to recalculate each tile.

Source:

<static> findShapedTileLine(tiles, horizontal, indexFrom, length) → {Array}

Finds the first line in either horizontal or vertical direction from tiles. Tip: when converting tiles to shapes, is usually better to call ig.utilstile.shapesFromCollisionMap.

Parameters:
Name Type Argument Default Description
tiles Array shaped tiles to search.
horizontal Boolean <optional>
false line is horizontal, else vertical.
indexFrom Number <optional>
0 index in tiles to start from.
length Number <optional>
0 max length of line.
Source:
Returns:
{ Array } list of tiles in line.

<static> getNonDuplicateSegmentVertices(tile, tileData, tilesAllowed) → {Array}

Checks and returns all of a tile's non-duplicate segment vertices. Tip: when converting tiles to shapes, is usually better to call ig.utilstile.shapesFromCollisionMap.

Parameters:
Name Type Description
tile Object shaped tile
tileData Array tiles data (2D array).
tilesAllowed Array tiles allowed to check against (flat array)
Source:
Returns:
{ Array } list of vertices

<static> getSegmentOverlapWithTile(vaA, vbA, normalCompare, tile) → {Boolean|Object}

Gets if a segment overlaps a tile edge. Tip: when converting tiles to shapes, is usually better to call ig.utilstile.shapesFromCollisionMap.

Parameters:
Name Type Description
vaA Number segment vertex a
vbA Number segment vertex b
normalCompare Vector2 | Object facing normal of segment
tile Object shaped tile to compare segment to
Source:
Returns:
{ Boolean | Object } no overlap = false, full overlap = true, partial overlap = object with area not overlapped

<static> getTouchingTilesByDirection(tile, direction, tileData, tilesAllowed) → {Array}

Gets touching tiles based on a direction. Tip: when converting tiles to shapes, is usually better to call ig.utilstile.shapesFromCollisionMap.

Parameters:
Name Type Description
tile Object shaped tile
direction Object direction to look (normalized)
tileData Array tiles data (2D array)
tilesAllowed Array tiles allowed to check against (flat array)
Source:
Returns:
{ Array } all tiles directly touching a tile based on direction

<static> isTileClimbable(tileId) → {Boolean}

Gets if a tile is climbable.

Parameters:
Name Type Description
tileId Number tile id.
Source:
Returns:
{ Boolean } whether tile is climbable

<static> isTileClimbableOneWay(tileId) → {Boolean}

Gets if a tile is climbable and one way.

Parameters:
Name Type Description
tileId Number tile id.
Source:
Returns:
{ Boolean } whether tile is climbable and one way

<static> isTileClimbableStairs(tileId) → {Boolean}

Gets if a tile is stairs.

Parameters:
Name Type Description
tileId Number tile id.
Source:
Returns:
{ Boolean } whether tile is stairs

<static> isTileOneWay(tileId) → {Boolean}

Gets if a tile is one-way.

Parameters:
Name Type Description
tileId Number tile id.
Source:
Returns:
{ Boolean } whether tile is one-way

<static> isTileWalkable(tileId) → {Boolean}

Gets if a tile is walkabke.

Parameters:
Name Type Description
tileId Number tile id.
Source:
Returns:
{ Boolean } whether tile is one-way

<static> isTileWalkableStrict(tileId) → {Boolean}

Gets if a tile is strictly walkabke.

Parameters:
Name Type Description
tileId Number tile id.
Source:
Returns:
{ Boolean } whether tile is one-way

<static> rebuild(collisionMap)

Rebuilds tile shapes (vertices, segments, normals) based on a collision map.
- this is called automatically by ig.GameExtended#buildLevel, and only does rebuild if collision map tiledef differs from current tiledef IMPORTANT: if using a ig.PathfindingMap, the tilesize must match the ig.CollisionMap's tilesize!

Parameters:
Name Type Description
collisionMap ig.CollisionMap map with tile definition.
Source:

<static> shapedTilesToShapes(tiles, data, options) → {Array}

Converts a list of tiles with vertices into shapes. Tip: when converting tiles to shapes, is usually better to call ig.utilstile.shapesFromCollisionMap.

Parameters:
Name Type Description
tiles Array shaped tiles to convert
data Array 2d list of all tiles in map
options Object options object
Source:
Returns:
{ Array } list of shapes

<static> shapeFromTile(tileId, tileDefs) → {Object}

Generates boolean for empty or, if solid, vertices and segments in clockwise order from a tile. Tip: when converting tiles to shapes, is usually better to call ig.utilstile.shapesFromCollisionMap.

Parameters:
Name Type Argument Default Description
tileId String | Number tile id
tileDefs Object <optional>
ig.CollisionMap.defaultTileDef map of tile ids to their definitions
Source:
Returns:
{ Object } object with array of 0 to 5 vertices and array of 0 to 5 segments

<static> shapesFromCollisionMap(map, options) → {Array}

Extracts all shapes from an impact collision map, with vertices in clockwise order.
- this method does its best to intelligently combine tiles into as big of shapes as it can
- shapes consist of an x and y position, and a settings object with an array of vertices and a size object

Parameters:
Name Type Description
map ig.CollisionMap map data object
options Object options object
Source:
Returns:
{ Array } array of shapes including a list of oneWays, edges, and climbables
Example
// options is a plain object
options = {};
// we can ignore climbable tiles when extracting shapes
options.ignoreClimbables = true;
// we can ignore one way tiles when extracting shapes
options.ignoreOneWays = true;
// we can ignore solid tiles when extracting shapes
options.ignoreSolids = true;
// we can keep the outer boundary edge shape when converting a collision map
// but by default, the outer boundary is thrown away
// this is because it is unlikely the player will ever be outside the level
// so the outer boundary edge is usually useless
options.retainBoundaryOuter = true;
// we can throw away the inner boundary edge shape
// i.e. the edge shape on the inside of the outer boundary
options.discardBoundaryInner = true;
// we can also throw away any shapes inside the inner boundary edge shape
options.discardBoundaryInner = true;
// we can force rectangles to be created instead of contour shapes
// this is useful when we may have concave shapes that don't play nice with bounding boxes
options.rectangles = true;
// we can force just climbables to be rectangles
options.contourClimbables = false;
// we can force just one ways to be rectangles
options.contourOneWays = false;
// we can force shapes to only be constructed by tiles of the same type / id
options.groupByTileId = true;
// we can throw away all collinear vertices to improve performance
options.discardCollinear = true;
// we can reverse the shape vertex order to counter-clockwise
options.reverse = true;

<static> stepShapedTileHorizontally(tiles, tileFrom) → {Object}

Attempts to step to the next tile horizontally. Tip: when converting tiles to shapes, is usually better to call ig.utilstile.shapesFromCollisionMap.

Parameters:
Name Type Description
tiles Array shaped tiles to search
tileFrom Object tile stepping from
Source:
Returns:
{ Object } next tile, or current tile if next not found

<static> stepShapedTileVertically(tiles, tileFrom) → {Object}

Attempts to step to the next tile vertically. Tip: when converting tiles to shapes, is usually better to call ig.utilstile.shapesFromCollisionMap.

Parameters:
Name Type Description
tiles Array shaped tiles to search
tileFrom Object tile stepping from
Source:
Returns:
{ Object } next tile, or current tile if next not found

<static> unload()

Unload tile shapes. IMPORTANT: this is called automatically by ig.GameExtended#unloadLevel.

Source:

<static> verticesFromTile(tileId, tileDefs) → {Array}

Generates boolean for empty or, if solid, vertices in clockwise order from a tile.9
- this function makes some assumptions about tiles, such as being either 3, 4, or 5 sided, always having a corner, and being convex Tip: when converting tiles to shapes, is usually better to call ig.utilstile.shapesFromCollisionMap.

Parameters:
Name Type Argument Default Description
tileId String | Number tile id
tileDefs Object <optional>
ig.CollisionMap.defaultTileDef map of tile ids to their definitions
Source:
Returns:
{ Array } array of 0 to 5 vertices

<static> verticesToContours(vertices, options) → {Array}

Converts a list of vertices into contours. Tip: when converting tiles to shapes, is usually better to call ig.utilstile.shapesFromCollisionMap.

Parameters:
Name Type Description
vertices Array list of vertices
options Object options object
Source:
Returns:
{ Array } list of contours