Fork me on GitHub
View source

package haxepunk.graphics.tile

class Tilemap


extends Graphic

A rendered grid of tiles.

Constructor

View source

new (tileset : TileType, width : Int, height : Int, tileWidth : Int, tileHeight : Int, tileMarginWidth : Int = 0, tileMarginHeight : Int = 0, tileOffsetX : Int = 0, tileOffsetY : Int = 0) : 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.

tileMarginWidth   

Tile horizontal spacing.

tileMarginHeight   

Tile vertical spacing.

Variables

angle : Float

Rotation of the tilemap, in degrees.

read only columns : Int

How many columns the tilemap has.

read only height : Int

Height of the tilemap.

read only rows : Int

How many rows the tilemap has.

scale : Float

Scale of the tilemap, effects both x and y scale.

scaleX : Float

X scale of the tilemap.

scaleY : Float

Y scale of the tilemap.

read only tileCount : Int

How many tiles the tilemap has.

read only tileHeight : Int

The tile height.

read only tileMarginHeight : Int

The tile vertical margin of tile.

read only tileMarginWidth : Int

The tile horizontal margin of tile.

read only tileWidth : Int

The tile width.

usePositions : Bool

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

read only width : Int

Width of the tilemap.

Functions

View source

centerOrigin () : Void

Centers the origin of the tilemap based on it's full width/height.

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

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

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.