Fork me on GitHub
View source

package com.haxepunk.graphics

class Tilemap


extends Canvas

A canvas to which Tiles can be drawn for fast multiple tile rendering.

Constructor

View source

new (tileset : TileType, width : Int, height : Int, tileWidth : Int, tileHeight : Int, tileSpacingWidth : Int = 0, tileSpacingHeight : Int = 0, opaqueTiles : Bool = true) : Void

Constructor.


Parameters:
tileset   

The source tileset image.

width   

Width of the tilemap, in pixels.

height   

Height of the tilemap, in pixels.

tileWidth   

Tile width.

tileHeight   

Tile height.

tileSpacingWidth   

Tile horizontal spacing.

tileSpacingHeight   

Tile vertical spacing.

opaqueTiles   

Indicates if this tileset contains only opaque tiles (defaults to true). Only used in Flash .

Variables

read only columns : Int

How many columns the tilemap has.

read only opaqueTiles : Bool

If false, whenever you call setTile or one of the load methods, clears the affected Tilemap areas before redrawing. Only used on Flash targets and with tilesets that contain transparency.

read only rows : Int

How many rows the tilemap has.

smooth : Bool

Default value: false if HXP.stage.quality is LOW, true otherwise.

read only tileCount : Int

How many tiles the tilemap has.

read only tileHeight : Int

The tile height.

read only tileSpacingHeight : Int

The tile vertical spacing of tile.

read only tileSpacingWidth : Int

The tile horizontal spacing of tile.

read only tileWidth : Int

The tile width.

usePositions : Bool

If x/y positions should be used instead of columns/rows.

Functions

View source

clearRect (column : Int, row : Int, width : Int = 1, height : Int = 1) : Void

Clears the rectangular region of tiles.


Parameters:
column   

First tile column.

row   

First tile row.

width   

Width in tiles.

height   

Height in tiles.

View source

clearTile (column : Int, row : Int) : Void

Clears the tile at the position.


Parameters:
column   

Tile column.

row   

Tile row.

View source

createGrid (solidTiles : Array<Int>, grid : Grid) : Null<Grid>

Create a Grid object from this tilemap.


Parameters:
solidTiles   

Array of tile indexes that should be solid.

grid   

A grid to use instead of creating a new one, the function won't check if the grid is of correct dimension.


Returns:

The grid with a tile solid if the tile index is in [solidTiles].

View source

getIndex (tilesColumn : Int, tilesRow : Int) : Int

Calculates the index of a tile, based on its column and row in the tileset.


Parameters:
tilesColumn   

Tileset column.

tilesRow   

Tileset row.


Returns:

Index of the tile.

View source

getTile (column : Int, row : Int) : Int

Gets the tile index at the position.


Parameters:
column   

Tile column.

row   

Tile row.


Returns:

The tile index.

View source

getX (index : Int) : Int

Calculates the column of a tile, based on its index in the tileset.


Parameters:
index   

Index of the tile.


Returns:

Column (x) of the tile.

View source

getY (index : Int) : Int

Calculates the row of a tile, based on its index in the tileset.


Parameters:
index   

Index of the tile.


Returns:

Row (y) of the tile.

View source

loadFrom2DArray (array : Array<Array<Int>>) : Void

Set the tiles from an array. The array must be of the same size as the Tilemap.


Parameters:
array   

The array to load from.

View source

loadFromString (str : String, columnSep : String = ",", rowSep : String = "\n") : Void

Loads the Tilemap tile index data from a string. The implicit array should not be bigger than the Tilemap.


Parameters:
str   

The string data, which is a set of tile values separated by the columnSep and rowSep strings.

columnSep   

The string that separates each tile value on a row, default is ",".

rowSep   

The string that separates each row of tiles, default is "\n".

View source

saveToString (columnSep : String = ",", rowSep : String = "\n") : String

Saves the Tilemap tile index data to a string.


Parameters:
columnSep   

The string that separates each tile value on a row, default is ",".

rowSep   

The string that separates each row of tiles, default is "\n".


Returns:

The string version of the array.

View source

setRect (column : Int, row : Int, width : Int = 1, height : Int = 1, index : Int = 0) : Void

Sets a rectangular region of tiles to the index.


Parameters:
column   

First tile column.

row   

First tile row.

width   

Width in tiles.

height   

Height in tiles.

index   

Tile index.

View source

setTile (column : Int, row : Int, index : Int = 0) : Void

Sets the index of the tile at the position.


Parameters:
column   

Tile column.

row   

Tile row.

index   

Tile index from the tileset to show. (Or -1 to show the tile as blank.)

View source

shiftTiles (columns : Int, rows : Int, wrap : Bool = false) : Void

Shifts all the tiles in the tilemap.


Parameters:
columns   

Horizontal shift.

rows   

Vertical shift.

wrap   

If tiles shifted off the canvas should wrap around to the other side.