Tilemap

Tile maps generated with Tiled tile map editor.

new game.Tilemap(json, [skipLoad])

Parameters:

  • json String

    Filename of Tiled JSON file

  • skipLoad Boolean (optional)

    Skip loading

Properties

container Container

(No description yet)

height Number

Tilemap height in tiles.

json Object

JSON data of the tile map.

layers Object

Object of layers in the tile map. Key is layer name.

pixelHeight Number

Tilemap height in pixels.

pixelWidth Number

Tilemap height in pixels.

tileHeight Number

Tile height in pixels.

tiles Array

Array of all different tiles used in the tile map.

tilesets Array

Array of all tilesets used in the tile map.

tileWidth Number

Tile height in pixels.

width Number

Tilemap width in tiles.

Methods

addingLayer(layer) Boolean

Called when adding layer.

Parameters:

  • layer TileLayer

return true to skip the layer adding

addingTile(layer, tileId, tileIndex, x, y) Boolean

Called when adding tile.

Parameters:

  • layer TileLayer

    Tile layer

  • tileId Number

    Tile ID

  • tileIndex Number

    Tile index

  • x Number
  • y Number

return true to skip the tile adding

addTo(container)

Add tilemap to container

Parameters:

  • container Container
getLayer() Mixed

Get a specific layer from the JSON file

Layer object or false when not found

getLayerMatrix(layerName) Array

Gets the layer's tile id's presented in a matrix style array

Parameters:

  • layerName String

    The layer name from which we should get the data

Multi-dimensional array, rows and columns, containing tile ID's

getLayerNames() Array

Get the layer names defined in the JSON source

An array with the layer names

getTileIdAt(layerName, x, y) Number

Get the tile ID at specific coordinates

Parameters:

  • layerName String

    The layer name from which we should get the data

  • x Number

    x coordinate

  • y Number

    y coordinate

ID number or -1 when not found

getTileProperties(index) Object

Get tile properties for tileset.

Parameters:

  • index Number

    Tileset index

Tile properties object

initLayers()

Init layers.

initTiles()

Init tile sprites.

initTilesets()

Init tilesets.

load()

Load tilemap.

remove()

Remove tilemap container from it's parent

spriteFromTile(index) Sprite

Creates new Sprite from tile.

Parameters:

  • index Number

    Tileset index

New tile Sprite

tileAdded(layer, sprite, tileId, tileIndex, x, y) Boolean

Called when tile has been added.

Parameters:

  • layer TileLayer
  • sprite Sprite
  • tileId Number

    Tile ID

  • tileIndex Number

    Tile index

  • x Number
  • y Number

return true to not add the tile sprite to the tilemap container