Class: TilemapLayer

rune.tilemap.TilemapLayer(map, dataopt)

The rune.tilemap.TilemapLayer class represents a layer (buffer) within a Tilemap. Each layer has its own set of Tiles, which can be managed from the layer object. A Tilemap object automatically instantiates two layers; one for the back buffer, and one for the front buffer.

Constructor

new TilemapLayer(map, dataopt)

Creates a new object of TilemapLayer.
Parameters:
Name Type Attributes Description
map rune.tilemap.Tilemap Reference to the map to which the layer belongs.
data Array.<number> <optional>
Tilemap data.
Source:
See:

Extends

Members

(readonly) data :Array.<number>

Reference to this layer's mutable tile values, independent of source data. Read-only refers to the property; the returned array remains mutable.
Type:
  • Array.<number>
Inherited From:
Source:

(readonly) paths :rune.util.Paths

A stack of Path objects.
Type:
Inherited From:
Source:

visible :boolean

Whether the layer should be rendered or not. Useful for troubleshooting.
Type:
  • boolean
Inherited From:
Source:

Methods

clear() → {undefined}

Clears all map data.
Inherited From:
Source:
Returns:
Type
undefined

containsCell(column, row) → {boolean}

Checks whether integer cell coordinates lie within this layer. Coordinates are local columns and rows, independent of pixel size or origin.
Parameters:
Name Type Description
column number Zero-based local cell column.
row number Zero-based local cell row.
Inherited From:
Source:
Returns:
Type
boolean

getPath(sx, sy, gx, gy, mdopt, isBlockedopt, scopeopt) → {rune.util.Path}

Returns a Path object that describes the shortest path between two points within the layer data.
Parameters:
Name Type Attributes Default Description
sx number Starting position X in pixels.
sy number Starting position Y in pixels.
gx number Target position X in pixels.
gy number Target position Y in pixels.
md boolean <optional>
false Whether the Path object is allowed to include diagonal paths.
isBlocked function <optional>
Optional blocking rule using local cell (column, row).
scope Object <optional>
Callback scope.
Inherited From:
Source:
Returns:
Path through cell centers in pixels, or null if unreachable.
Type
rune.util.Path

getPathBetweenPoints(s, g, mdopt, isBlockedopt, scopeopt) → {rune.util.Path}

Returns a Path object that describes the shortest path between two points.
Parameters:
Name Type Attributes Default Description
s rune.geom.Point Starting point in pixels.
g rune.geom.Point Target point in pixels.
md boolean <optional>
false Whether the Path object is allowed to include diagonal paths.
isBlocked function <optional>
Optional blocking rule using local cell (column, row).
scope Object <optional>
Callback scope.
Inherited From:
Source:
Returns:
Path through cell centers in pixels, or null if unreachable.
Type
rune.util.Path

getTileAt(i) → {rune.tilemap.Tile}

Returns a temporary Tile describing the specified tile index. Each layer reuses one Tile for getTileAt(), getTileOf() and getTileOfPoint(). The next query on this layer overwrites the same object. Pathfinding and collision checks can also overwrite it through their internal tile queries. Do not retain, modify or dispose the returned Tile. Copy the needed values immediately when they must survive another layer operation. Use getTileValueAt() when only the numeric tile value is needed.
Parameters:
Name Type Description
i number Zero-based linear tile index.
Inherited From:
Source:
Returns:
Layer-owned reusable Tile, not an independent object.
Type
rune.tilemap.Tile
Example
var tile = layer.getTileAt(5);
var saved = {index: tile.index, value: tile.value, x: tile.x, y: tile.y};

getTileIndexesIn(x, y, w, h) → {Array.<number>}

Returns a list of Tile indices that fit within a specified rectangular area.
Parameters:
Name Type Description
x number Clipping area X in pixels.
y number Clipping area Y in pixels.
w number Clipping area width in pixels.
h number Clipping area height in pixels.
Inherited From:
Source:
Returns:
Type
Array.<number>

getTileIndexesInRect(r) → {Array.<number>}

Returns a list of Tile indices contained within a described Rectangle object.
Parameters:
Name Type Description
r rune.geom.Rectangle Rectangle in pixel coordinates.
Inherited From:
Source:
Returns:
Type
Array.<number>

getTileIndexOf(x, y) → {number}

Returns the tile index at a pixel position, accounting for the layer origin. The right and bottom boundaries are outside the layer.
Parameters:
Name Type Description
x number The x-coordinate of the position in pixels.
y number The y-coordinate of the position in pixels.
Inherited From:
Source:
Returns:
Tile index, or -1 for an invalid or outside position.
Type
number

getTileIndexOfPoint(p) → {number}

Returns the tile index at a pixel position, or -1 outside the layer.
Parameters:
Name Type Description
p rune.geom.Point Point in pixel coordinates.
Inherited From:
Source:
Returns:
Type
number

getTileOf(x, y) → {rune.tilemap.Tile}

Returns the layer's reusable Tile at a pixel position. Shares the temporary object used by getTileAt() and getTileOfPoint(). Later tile queries, pathfinding or collision checks on this layer can overwrite it. Copy needed values immediately; do not modify or dispose it.
Parameters:
Name Type Description
x number X coordinate in pixels.
y number Y coordinate in pixels.
Inherited From:
Source:
See:
Returns:
Layer-owned reusable Tile.
Type
rune.tilemap.Tile

getTileOfPoint(p) → {rune.tilemap.Tile}

Returns the layer's reusable Tile at a point's pixel coordinates. Shares the temporary object used by getTileAt() and getTileOf(). Later tile queries, pathfinding or collision checks on this layer can overwrite it. Copy needed values immediately; do not modify or dispose it.
Parameters:
Name Type Description
p rune.geom.Point Point in pixel coordinates.
Inherited From:
Source:
See:
Returns:
Layer-owned reusable Tile.
Type
rune.tilemap.Tile

getTileValueAt(i) → {number}

Returns the tile value of a specific tile index.
Parameters:
Name Type Description
i number Zero-based linear tile index.
Inherited From:
Source:
Returns:
Type
number

getTileValueAtCell(column, row) → {number}

Returns a tile value using local cell coordinates instead of a linear index. Returns zero for cells outside the layer or non-integer coordinates.
Parameters:
Name Type Description
column number Zero-based local cell column.
row number Zero-based local cell row.
Inherited From:
Source:
Returns:
Type
number

getTileValueOf(x, y) → {number}

Returns the tile value at a pixel position, or zero outside the layer.
Parameters:
Name Type Description
x number Position X in pixels.
y number Position Y in pixels.
Inherited From:
Source:
Returns:
Type
number

getTileValueOfPoint(p) → {number}

Return the tile value of a specific position, defined via a Point object.
Parameters:
Name Type Description
p rune.geom.Point Point in pixel coordinates.
Inherited From:
Source:
Returns:
Type
number

getTileValuesIn(x, y, w, h) → {Array.<number>}

Returns tile values that fit within a specific rectangle.
Parameters:
Name Type Description
x number Clipping area X in pixels.
y number Clipping area Y in pixels.
w number Clipping area width in pixels.
h number Clipping area height in pixels.
Inherited From:
Source:
Returns:
Type
Array.<number>

getTileValuesInRect(r) → {Array.<number>}

Returns tile values that fit within a specific rectangle object.
Parameters:
Name Type Description
r rune.geom.Rectangle Rectangle in pixel coordinates.
Inherited From:
Source:
Returns:
Type
Array.<number>

hitTest(obj, callbackopt, scopeopt) → {boolean}

Evaluates whether the tilemap layer overlaps another object.
Parameters:
Name Type Attributes Description
obj rune.display.Stage | rune.display.InteractiveObject | rune.display.DisplayGroup | rune.tilemap.TilemapLayer | rune.geom.Point | Array The object to be evaluated.
callback function <optional>
Executed for each detected collision.
scope Object <optional>
Scope of execution for the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestAndSeparate(obj, callbackopt, scopeopt) → {boolean}

Evaluates and resolves collision between the tilemap layer and an object.
Parameters:
Name Type Attributes Description
obj rune.display.Stage | rune.display.InteractiveObject | rune.display.DisplayGroup | rune.tilemap.TilemapLayer | Array The object to be evaluated.
callback function <optional>
Executed for each detected collision.
scope Object <optional>
Scope of execution for the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestAndSeparateChildrenOf(parent, callbackopt, scopeopt) → {boolean}

Evaluates and resolves collision against child objects.
Parameters:
Name Type Attributes Description
parent rune.display.DisplayObjectContainer The parent object to evaluate.
callback function <optional>
Executed for each detected collision.
scope Object <optional>
Scope of execution for the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestAndSeparateContentOf(array, callbackopt, scopeopt) → {boolean}

Evaluates and resolves collision against objects in an array.
Parameters:
Name Type Attributes Description
array Array The array object to evaluate.
callback function <optional>
Executed for each detected collision.
scope Object <optional>
Scope of execution for the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestAndSeparateGroup(group, callbackopt, scopeopt) → {boolean}

Evaluates and resolves collision against members of a group.
Parameters:
Name Type Attributes Description
group rune.display.DisplayGroup The group to evaluate.
callback function <optional>
Executed for each detected collision.
scope Object <optional>
Scope of execution for the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestAndSeparateObject(obj, callbackopt, scopeopt) → {boolean}

Resolves horizontal contacts against all candidate tiles before resolving vertical contacts. Candidates are recalculated after horizontal separation so internal wall seams cannot act as floors or ceilings.
Parameters:
Name Type Attributes Description
obj rune.display.InteractiveObject The object to evaluate.
callback function <optional>
Executed for each detected collision.
scope Object <optional>
Scope of execution for the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestChildrenOf(parent, callbackopt, scopeopt) → {boolean}

Evaluates whether the tilemap layer overlaps child objects.
Parameters:
Name Type Attributes Description
parent rune.display.DisplayObjectContainer The object to evaluate.
callback function <optional>
Executed for each detected collision.
scope Object <optional>
Scope of execution for the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestContentOf(array, callbackopt, scopeopt) → {boolean}

Evaluates every array entry using the same rules as hitTest(). Supports points, interactive objects, groups, stages and nested arrays. Unsupported entries are ignored; callbacks run for all detected contacts.
Parameters:
Name Type Attributes Description
array Array The array to evaluate.
callback function <optional>
Executed for each detected collision.
scope Object <optional>
Scope of execution for the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestGroup(group, callbackopt, scopeopt) → {boolean}

Evaluates whether the tilemap layer overlaps any member of a group.
Parameters:
Name Type Attributes Description
group rune.display.DisplayGroup The group to evaluate.
callback function <optional>
Executed for each detected collision.
scope Object <optional>
Scope of execution for the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestObject(obj, callbackopt, scopeopt) → {boolean}

Evaluates whether the tilemap layer overlaps another interactive object.
Parameters:
Name Type Attributes Description
obj rune.display.InteractiveObject The object to evaluate.
callback function <optional>
Executed for each detected collision.
scope Object <optional>
Scope of execution for the callback method.
Inherited From:
Source:
Returns:
Type
boolean

hitTestPoint(point, callbackopt, scopeopt) → {boolean}

Evaluates whether a point overlaps a solid tile.
Parameters:
Name Type Attributes Description
point rune.geom.Point Point in pixel coordinates.
callback function <optional>
Executed for each detected collision.
scope Object <optional>
Scope of execution for the callback method.
Inherited From:
Source:
Returns:
Type
boolean

setTileValueAt(i, v) → {undefined}

Sets a tile value at a specified index.
Parameters:
Name Type Description
i number Zero-based linear tile index.
v number Value.
Inherited From:
Source:
Returns:
Type
undefined

setTileValueAtCell(column, row, value) → {undefined}

Sets a tile value using local cell coordinates instead of a linear index. Ignores cells outside the layer and non-integer coordinates. Pixel size and owner position do not affect these coordinates. Uses setTileValueAt() for value conversion and render-cache invalidation.
Parameters:
Name Type Description
column number Zero-based local cell column.
row number Zero-based local cell row.
value number Tile value to set.
Inherited From:
Source:
See:
Returns:
Type
undefined
Example
layer.setTileValueAtCell(2, 1, 5);
var value = layer.getTileValueAtCell(2, 1);

setTileValueIn(x, y, w, h, v) → {undefined}

Sets a tile value for all tiles that fit within a specific rectangular area.
Parameters:
Name Type Description
x number Area X in pixels.
y number Area Y in pixels.
w number Area width in pixels.
h number Area height in pixels.
v number The value to be set.
Inherited From:
Source:
Returns:
Type
undefined

setTileValueInRect(r, v) → {undefined}

Sets a tile value for all tiles that fit within a specific rectangular area.
Parameters:
Name Type Description
r rune.geom.Rectangle Rectangle in pixel coordinates.
v number The value to be set.
Inherited From:
Source:
Returns:
Type
undefined

setTileValueOf(x, y, v) → {undefined}

Sets a tile value at a pixel position. Positions outside the layer are ignored.
Parameters:
Name Type Description
x number Position X in pixels.
y number Position Y in pixels.
v number The value to be set.
Inherited From:
Source:
Returns:
Type
undefined

setTileValueOfPoint(p, v) → {undefined}

Sets a tile value for a tile at a specific position.
Parameters:
Name Type Description
p rune.geom.Point Point in pixel coordinates.
v number The value to be set.
Inherited From:
Source:
Returns:
Type
undefined