Kiwi.GameObjects.Tilemap.TileMap Class
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]
Parameters:
-
state
Kiwi.StateThe state that this Tilemap is on.
-
[tileMapDataKey]
String optionalThe Data key for the JSON you would like to use.
-
[atlas]
Kiwi.Textures.TextureAtlas optionalThe texture atlas that you would like the tilemap layers to use.
-
[startingCell=0]
Number optionalThe number for the initial cell that the first TileType should use. See 'createFromFileStore' for more information.
Returns:
Item Index
Methods
Methods
_generateTypesFromTileset
-
tilesetData
-
atlas
-
startingCell
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
ArrayThe tileset part of the JSON.
-
atlas
Kiwi.Textures.TextureAtlasThe Texture atlas which contains the cells that the new TileTypes will use.
-
startingCell
NumberThe first cell number that would be used.
createFromFileStore
-
tileMapData
-
atlas
-
[startingCell=0]
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
AnyThis can either
-
atlas
Kiwi.Textures.TextureAtlasThe texture atlas that you would like the tilemap layers to use.
-
[startingCell=0]
Number optionalThe 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]
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
StringName of the TileMap.
-
atlas
Kiwi.Textures.TextureAtlasThe TextureAtlas that this layer should use.
-
data
NumberThe tile information.
-
[w=this.width]
Number optionalThe width of the whole tile map. In Tiles.
-
[h=this.height]
Number optionalThe height of the whole tile map. In Tiles.
-
[x=0]
Number optionalThe position of the tilemap on the x axis. In pixels.
-
[y=0]
Number optionalThe position of the tilemap on the y axis. In pixels.
-
[tw=this.tileWidth]
Number optionalThe width of a single tile.
-
[th=this.tileHeight]
Number optionalThe height of a single tile.
-
[orientation]
String optionalThe orientation of the tilemap. Defaults to the same as this TileMap.
Returns:
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]
Generates a single new TileType. Returns the TileType that was generated.
Parameters:
-
[cell=-1]
Number optionalThe cell that is to be used. Default is -1 (which means none)
Returns:
The TileType generated.
createTileTypes
-
cells
Creates a new TileType for each cell that you pass.
Parameters:
-
cells
NumberThe cells that you want a new TileType created for.
Returns:
The TileTypes generated.
createTileTypesByRange
-
cellStart
-
range
Used to create a number of TileTypes based starting cell number and how many you want from there.
Parameters:
-
cellStart
NumberThe starting number of the cell.
-
range
NumberHow many cells (from the starting cell) should be created.
Returns:
The TileTypes generated.
getLayer
-
num
Returns the layer with the number associated with it in the layers array.
Parameters:
-
num
NumberNumber of the Layer you would like to get.
Returns:
getLayerByName
-
name
Get a layer by the name that it was given upon creation. Returns null if no layer with that name was found.
Parameters:
-
name
StringName of the layer you would like to select.
Returns:
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:
"TileMap"
setCell
-
type
-
cell
Changes a single cellIndex that a TileType is to use when it is rendered.
Parameters:
-
type
NumberThe number of the TileType that is to change.
-
cell
NumberThe new cellIndex it should have.
setCellsByRange
-
typeStart
-
cellStart
-
range
Changes a range of cellIndexs for Tiles the same range of TileTypes.
Parameters:
-
typeStart
NumberThe starting TileType that is to be modified.
-
cellStart
NumberThe starting cellIndex that the first TileType should have.
-
range
NumberHow many times it should run.
setTo
-
tileWidth
-
tileHeight
-
width
-
height
Method to set the default TileMap properties. Useful when wanting to create tilemaps programmatically.
Parameters:
-
tileWidth
NumberThe width of a single tile.
-
tileHeight
NumberThe height of a single tile.
-
width
NumberThe width of the whole map.
-
height
NumberThe height of the whole map.
Properties
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.
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.