Class: Tilemap

rune.tilemap.Tilemap()

The rune.tilemap.Tilemap class, represents an orthogonal grid (Tilemap) of textured rectangles (Tiles). A Tilemap contains two layers (buffers) of tiles; back and front, where each layer is represented by a TilemapLayer object. Rune's Scene objects automatically instantiate their own Tilemap. Tile sizes and map width/height are in pixels; widthInTiles and heightInTiles are cell counts. Layer methods document whether they take pixel positions, local cell coordinates or linear tile indices.

Constructor

new Tilemap()

Creates a new Tilemap object.
Source:
See:

Members

(readonly) back :rune.tilemap.TilemapLayer

Reference to the Tilemap's rear buffer, i.e. the bottom layer in the layer hierarchy. Note that DisplayObjects placed on the stage are rendered on top of this buffer.
Type:
Source:

(readonly) front :rune.tilemap.TilemapLayer

Reference to the Tilemap's front buffer, i.e. the top layer in the layer hierarchy. Note that this layer is rendered on top of both the DisplayObjects placed on the stage, as well as the Tiles included in the back buffer.
Type:
Source:

(readonly) height :number

The current height of the map, specified in pixels.
Type:
  • number
Source:

(readonly) heightInTiles :number

The height of the tile map, given in number of tiles.
Type:
  • number
Source:

(readonly) name :string

The name of the current map. The name is retrieved from the map data (JSON) when the map is loaded. If no name is declared in the map data, the name of the map data file is used as the name.
Type:
  • string
Source:

(readonly) numTiles :number

The total number of Tiles included in the current map.
Type:
  • number
Source:

(readonly) texture :HTMLImage

Reference to the texture the map uses for its Tiles.
Type:
  • HTMLImage
Source:

(readonly) tileHeight :number

The height of a Tile, given in pixels.
Type:
  • number
Source:

(readonly) tileWidth :number

The width of a Tile, given in pixels.
Type:
  • number
Source:

(readonly) width :number

The current width of the map, specified in pixels.
Type:
  • number
Source:

(readonly) widthInTiles :number

The width of the tile map, given in number of tiles.
Type:
  • number
Source:

Methods

clear() → {undefined}

Resets the map.
Source:
Returns:
Type
undefined

getBlock(v) → {rune.tilemap.Block}

Creates and returns a new Block object based on a tile value. The method can be used to generate tiles represented by Sprite objects.
Parameters:
Name Type Description
v number Tile value.
Source:
Returns:
Type
rune.tilemap.Block

getProperty(name, defaultValueopt) → {*}

Reads an own, top-level property from the loaded map's source JSON data. Nested properties are accessed through the returned object, not through path syntax. Objects and arrays are returned as independent deep copies. Changes to the running tilemap are not reflected in the source data. The default value is returned unchanged only if the property is missing, including before loading a map and after clear(). Values such as false, zero, an empty string and null are preserved. Without a default value, a missing property returns undefined.
Parameters:
Name Type Attributes Description
name string Property name.
defaultValue * <optional>
Value to return if the property is missing.
Source:
Returns:
Property value, a deep copy, or the supplied default value.
Type
*

getTilePropertiesOf(v) → (nullable) {Object}

Returns the map-owned properties for a tile value, or null if undefined. Values in the same values group return the same object, so property edits affect the whole group. Definitions and nested properties are independent of the source resource and other map instances. Editing value or values does not change the lookup established when the map was loaded.
Parameters:
Name Type Description
v number | string Tile value.
Source:
Returns:
The shared group definition within this map, or null.
Type
Object

getTileTextureRectOf(v) → {rune.geom.Rectangle}

Returns a rectangle object that describes a value's location in the texture atlas. The method is mainly intended for internal use, but can be useful if you want to copy a "piece" of the texture atlas. The same map-owned Rectangle is reused and overwritten on every call, including calls made internally during rendering. Do not modify or retain it as a snapshot. Use Rectangle.clone() for an independent copy, or Rectangle.copy() to copy its values into a caller-owned rectangle.
Parameters:
Name Type Description
v number Tile value.
Source:
See:
Returns:
Map-owned reusable rectangle.
Type
rune.geom.Rectangle
Example
var saved = rune.geom.Rectangle.clone(map.getTileTextureRectOf(3));

load(name) → {undefined}

Loads a map from resource data. Each layer owns a copy of its tile values, so edits do not affect the resource or other map instances. Loading the same resource again restores its original tile values. If loading fails, the current layers, live tile edits and map properties are preserved. Width, height, tileWidth and tileHeight must be positive safe integers. The cell count must fit a JavaScript array, and pixel dimensions must remain safe integers. Tile definitions accept either value or a non-empty values array. Each tile value must be a unique non-negative safe integer. Legacy value entries also accept numeric strings. Definitions are copied per map, while grouped values share one definition within the map.
Parameters:
Name Type Description
name string The name of the resource that represents the map data.
Source:
Throws:
  • In case of missing or corrupt map data.
    Type
    Error
  • If dimensions are invalid or exceed supported ranges.
    Type
    RangeError
Returns:
Type
undefined