Uses a hash grid to determine collision, faster than using hundreds of Entities for tiled levels, etc.
Constructor
new (width : Int, height : Int, tileWidth : Int, tileHeight : Int, x : Int = 0, y : Int = 0) : Void
Constructor. The actual size of the grid is determined by dividing the width/height by tileWidth/tileHeight, and stored in the properties columns/rows.
Parameters:
width | Width of the grid, in pixels. | |
height | Height of the grid, in pixels. | |
tileWidth | Width of a grid tile, in pixels. | |
tileHeight | Height of a grid tile, in pixels. | |
x | X offset of the grid. | |
y | Y offset of the grid. |
Variables
usePositions : Bool
If x/y positions should be used instead of columns/rows (the default). Columns/rows means screen coordinates relative to the width/height specified in the constructor. X/y means grid coordinates, relative to the grid size.
Functions
clearRect (column : Int = 0, row : Int = 0, width : Int = 1, height : Int = 1) : Void
Makes the rectangular region of tiles non-solid.
Parameters:
column | First column. | |
row | First row. | |
width | Columns to fill. | |
height | Rows to fill. |
clearTile (column : Int = 0, row : Int = 0) : Void
Makes the tile non-solid.
Parameters:
column | Tile column. | |
row | Tile row. |
getTile (column : Int = 0, row : Int = 0) : Bool
Gets the value of a tile.
Parameters:
column | Tile column. | |
row | Tile row. |
Returns:
tile value.
loadFrom2DArray (array : Array<Array<Int>>) : Void
Loads the grid data from an array.
Parameters:
array | The array data, which is a set of tile values (0 or 1) |
loadFromString (str : String, columnSep : String = ",", rowSep : String = "\n") : Void
Loads the grid data from a string.
Parameters:
str | The string data, which is a set of tile values (0 or 1) 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". |
saveToString (columnSep : String = ",", rowSep : String = "\n", solid : String = "true", empty : String = "false") : String
Saves the grid 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 grid.
setRect (column : Int = 0, row : Int = 0, width : Int = 1, height : Int = 1, solid : Bool = true) : Void
Sets the value of a rectangle region of tiles.
Parameters:
column | First column. | |
row | First row. | |
width | Columns to fill. | |
height | Rows to fill. | |
solid | Value to fill. |
setTile (column : Int = 0, row : Int = 0, solid : Bool = true) : Void
Sets the value of the tile.
Parameters:
column | Tile column. | |
row | Tile row. | |
solid | If the tile should be solid. |