Skip to content
markandgo edited this page Jan 6, 2013 · 6 revisions

The grid is a 2d data structure. It makes accessing data and iterating over it is much easier than a standard 2d array. TileLayers extend this class and uses it to store tiles.

Public

Data

Grid.cells (default: {})
The cells of the grid. This is just a standard 2d array that stores all of the data.

###Functions Grid:get() (x, y)
Gets data from a single cell. Returns nil if the cell does not exist.

Grid:set() (x, y, value)
Sets the value of a single cell.

Grid:setArea() (startX, startY, endX, endY, value)
Sets the value to a rectangle area of cells.

Grid:iterate() ()
Iterates over all existing values of the grid. Order is not guaranteed.

Grid:rectangle() (startX, startY, width, height, includeNil)
Iterates over a rectangle shape of cells. Order is left-to-right, top-to-bottom. If includeNil is not true then empty cells are ignored.

Grid:line() (startX, startY, endX, endY, noDiag, includeNil)
Iterate over a line shape of cells. Set noDiag to true to keep from traversing diagonally. If includeNil is not true then empty cells are ignored.

Grid:circle() (cx, cy, r, includeNil)
Iterate over a circle shape of cells. If includeNil is not true then empty cells are ignored.

Grid:clean() ()
Cleans the grid of empty rows.

Grid:clear() ()
Clears the grid of all cells.

Grid:``call() (x, y)
Calling the grid like a function will make it act like Grid:get().


See Also

TileLayer Home