API Docs for: 1.4.0
Show:

Kiwi.GameObjects.Tilemap.TileMap Class

Module: Tilemap
Parent Module: GameObjects

A TileMap handles the creation of TileMapLayers and the TileTypes that they use. Since a TileMap isn't a Entity itself you cannot add it to the Stage inorder to render that it manages, Instead you have to add each layer lies within it. This way you can have other GameObjects behind/in-front of layers.

Constructor

Kiwi.GameObjects.Tilemap.TileMap

(
  • state
  • [tileMapDataKey]
  • [atlas]
  • [startingCell=0]
)
TileMap

Parameters:

  • state Kiwi.State

    The state that this Tilemap is on.

  • [tileMapDataKey] String optional

    The Data key for the JSON you would like to use.

  • [atlas] Kiwi.Textures.TextureAtlas optional

    The texture atlas that you would like the tilemap layers to use.

  • [startingCell=0] Number optional

    The number for the initial cell that the first TileType should use. See 'createFromFileStore' for more information.

Returns:

TileMap:

Methods

_generateTypesFromTileset

(
  • tilesetData
  • atlas
  • startingCell
)
private

Generates new TileTypes based upon the Tileset information that lies inside the Tiled JSON. This is an INTERNAL method, which is used when the createFromFileStore method is executed.

Parameters:

  • tilesetData Array

    The tileset part of the JSON.

  • atlas Kiwi.Textures.TextureAtlas

    The Texture atlas which contains the cells that the new TileTypes will use.

  • startingCell Number

    The first cell number that would be used.

createFromFileStore

(
  • tileMapData
  • atlas
  • [startingCell=0]
)
public

Creates new tilemap layers from a JSON file that you pass (has to be in the Tiled Format). The texture atlas you pass is that one that each TileMapLayer found in the JSON will use, You can change the TextureAtlas afterwards. New TileTypes will automatically be created. The number is based on the Tileset parameter of the JSON. The cell used for new TileTypes will begin at 0 and increment each time a new TileType is created (and a cell exists). Otherwise new TileTypes will start will a cell of -1 (none).

Parameters:

  • tileMapData Any

    This can either

  • atlas Kiwi.Textures.TextureAtlas

    The texture atlas that you would like the tilemap layers to use.

  • [startingCell=0] Number optional

    The number for the initial cell that the first TileType should use. If you pass -1 then no new TileTypes will be created.

createNewLayer

(
  • name
  • atlas
  • data
  • [w=this.width]
  • [h=this.height]
  • [x=0]
  • [y=0]
  • [tw=this.tileWidth]
  • [th=this.tileHeight]
  • [orientation]
)
TileMapLayer public

Creates a new TileMapLayer with the details that are provided. If no width/height/tileWidth/tileHeight parameters are passed then the values will be what this TileMap has. If no 'data' is provided then the map will be automatically filled with empty Types of Tiles. Returns the new TileMapLayer that was created.

Parameters:

  • name String

    Name of the TileMap.

  • atlas Kiwi.Textures.TextureAtlas

    The TextureAtlas that this layer should use.

  • data Number

    The tile information.

  • [w=this.width] Number optional

    The width of the whole tile map. In Tiles.

  • [h=this.height] Number optional

    The height of the whole tile map. In Tiles.

  • [x=0] Number optional

    The position of the tilemap on the x axis. In pixels.

  • [y=0] Number optional

    The position of the tilemap on the y axis. In pixels.

  • [tw=this.tileWidth] Number optional

    The width of a single tile.

  • [th=this.tileHeight] Number optional

    The height of a single tile.

  • [orientation] String optional

    The orientation of the tilemap. Defaults to the same as this TileMap.

Returns:

TileMapLayer:

The TileMapLayer that was created.

createNewObjectLayer

() public

Eventually will create a new object layer. Currently does nothing.

createNewObjectLayer

() public

Eventually will create a new image layer. Currently does nothing.

createTileType

(
  • [cell=-1]
)
TileType public

Generates a single new TileType. Returns the TileType that was generated.

Parameters:

  • [cell=-1] Number optional

    The cell that is to be used. Default is -1 (which means none)

Returns:

TileType:

The TileType generated.

createTileTypes

(
  • cells
)
TileTypes public

Creates a new TileType for each cell that you pass.

Parameters:

  • cells Number

    The cells that you want a new TileType created for.

Returns:

TileTypes:

The TileTypes generated.

createTileTypesByRange

(
  • cellStart
  • range
)
TileTypes

Used to create a number of TileTypes based starting cell number and how many you want from there.

Parameters:

  • cellStart Number

    The starting number of the cell.

  • range Number

    How many cells (from the starting cell) should be created.

Returns:

TileTypes:

The TileTypes generated.

getLayer

(
  • num
)
TileMapLayer public

Returns the layer with the number associated with it in the layers array.

Parameters:

  • num Number

    Number of the Layer you would like to get.

Returns:

TileMapLayer:

getLayerByName

(
  • name
)
TileMapLayer public

Get a layer by the name that it was given upon creation. Returns null if no layer with that name was found.

Parameters:

  • name String

    Name of the layer you would like to select.

Returns:

TileMapLayer:

Either the layer with the name passed, or null if no Layer with that name was found.

objType

() String public

The type of object that it is.

Returns:

String:

"TileMap"

setCell

(
  • type
  • cell
)
public

Changes a single cellIndex that a TileType is to use when it is rendered.

Parameters:

  • type Number

    The number of the TileType that is to change.

  • cell Number

    The new cellIndex it should have.

setCellsByRange

(
  • typeStart
  • cellStart
  • range
)
public

Changes a range of cellIndexs for Tiles the same range of TileTypes.

Parameters:

  • typeStart Number

    The starting TileType that is to be modified.

  • cellStart Number

    The starting cellIndex that the first TileType should have.

  • range Number

    How many times it should run.

setTo

(
  • tileWidth
  • tileHeight
  • width
  • height
)
public

Method to set the default TileMap properties. Useful when wanting to create tilemaps programmatically.

Parameters:

  • tileWidth Number

    The width of a single tile.

  • tileHeight Number

    The height of a single tile.

  • width Number

    The width of the whole map.

  • height Number

    The height of the whole map.

Properties

game

Kiwi.Game public

The game that this TileMap is a part of.

height

Number public

The default height of all TileMapLayers when they are created. This value is in Tiles.

Default: 0

heightInPixels

Number public

The height of the tilemap in pixels. This value is READ ONLY.

layers

TileMapLayerBase public

A list of all of the TileMapLayers that exist on the TileMap.

orientation

String public

The orientation of the tilemap. Note: This value does not affect the individual layers.

properties

Object public

Any properties that were found in the JSON during creation.

state

Kiwi.State public

The state that this TileMap exists on.

tileHeight

Number public

The default height of a single tile that a TileMapLayer is told to have upon its creation.

Default: 0

tileTypes

TileType public

Is an Array containing all of the TileTypes that are available on the TileMap.

tileWidth

Number public

The default width of a single tile that a TileMapLayer is told to have upon its creation.

Default: 0

width

Number public

The default width of all TileMapLayers when they are created. This value is in Tiles.

Default: 0

widthInPixels

Number public

The width of the tilemap in pixels. This value is READ ONLY.