TileGrid

interface TileGrid(source)

A grid of columns by rows cells, each holding a Tile of tileSet, read through get. Column 0 is the left edge and row 0 the top, so cell (column, row) covers the area from column * tileSet.tileWidth, row * tileSet.tileHeight across one tile, in the grid's own units, and y points down as in the rest of the world.

Both kinds of tile layer are grids: a TileMapLayer, read from a map file and never changed, and a TileLayer, the component that draws and that a game may change. tileAt, solidRectangles, toTileLayer and Commands.spawnSolids work on either.

Has no sample because a TileSet needs a texture, which needs a GPU device.

Inheritors

Properties

Link copied to clipboard
abstract val columns: Int

Number of cells across.

Link copied to clipboard
abstract val rows: Int

Number of cells down.

Link copied to clipboard
abstract val tileSet: TileSet

The tile set every cell's tile belongs to, which gives the tile size and which tiles are solid.

Functions

Link copied to clipboard
abstract operator fun get(column: Int, row: Int): Tile

Returns the tile in the cell at column and row, Tile.EMPTY when the cell has none. For a cell at a position in world units, use tileAt.

Link copied to clipboard
fun TileGrid.solidRectangles(isSolid: (Tile) -> Boolean = tileSet::isSolid): List<Rect>

Returns rectangles that together cover exactly the cells whose tile isSolid, in the grid's own units, with (0, 0) at the grid's top-left corner, as few as this simple merge finds: each row's runs of neighboring solid cells become one rectangle, and runs that cover the same columns in the rows below grow it downwards. The rectangles are sorted from the top row down and left to right, and never overlap.

Link copied to clipboard

Returns the tile under the point (x, y), given in the grid's own units, with (0, 0) at the grid's top-left corner, or Tile.EMPTY when the point is outside the grid. For a TileLayer on an entity at (layerX, layerY) with scale 1, pass the world position minus the entity's, as in layer.tileAt(x - layerX, y - layerY).

Link copied to clipboard

Returns a new TileLayer holding a copy of this grid's cells and its TileGrid.tileSet, which a game may change and add to an entity to draw. The copy is independent: changing one does not change the other. Its sprite layer, color and visibility are TileLayer's defaults; Commands.spawnTileLayer copies a map layer's visibility and opacity too.