OrthoMap

Generic Tile Map structure that uses a single layer of tiles in an orthogonal grid.

This provides a 'flat' representation of multiple tile and object layers. T can be whatever type you would like to use to represent a single tile within the map.

An OrthoMap supports all the operations of dtiled.grid for working with RowCol coordinates. Additionally, it stores information about tile size for operations in pixel coordinate space.

Constructors

this
this(Tile[][] tiles, int tileWidth, int tileHeight)
this(RectGrid!(Tile[][]) grid, int tileWidth, int tileHeight)

Construct an orthogonal tilemap from a rectangular (non-jagged) grid of tiles.

Alias This

grid

Members

Functions

containsPoint
bool containsPoint(T pos)

True if the pixel position is within the map bounds.

coordAtPoint
auto coordAtPoint(T pos)

Get the grid location corresponding to a given pixel coordinate.

tileAtPoint
Tile tileAtPoint(T pos)

Get the tile at a given pixel position on the map. Throws if out of bounds.

tileCenter
PixelCoord tileCenter(RowCol coord)

Get the pixel offset of the center of the tile at the given coord.

tileOffset
PixelCoord tileOffset(RowCol coord)

Get the pixel offset of the top-left corner of the tile at the given coord.

Properties

tileHeight
auto tileHeight [@property getter]

Height of each tile in pixels

tileWidth
auto tileWidth [@property getter]

Width of each tile in pixels

Variables

grid
RectGrid!(Tile[][]) grid;

The underlying tile grid structure, surfaced with alias this.

Examples

Foreach over every tile in the map

1 import std.algorithm : equal;
2 
3 auto grid = [
4   [ 00, 01, 02, ],
5   [ 10, 11, 12, ],
6 ];
7 auto myMap = OrthoMap!int(grid, 32, 64);
8 
9 int[] result;
10 
11 foreach(tile ; myMap) result ~= tile;
12 
13 assert(result.equal([ 00, 01, 02, 10, 11, 12 ]));

Use ref with foreach to modify tiles

1 auto grid = [
2   [ 00, 01, 02, ],
3   [ 10, 11, 12, ],
4 ];
5 auto myMap = OrthoMap!int(grid, 32, 64);
6 
7 foreach(ref tile ; myMap) tile += 30;
8 
9 assert(myMap.tileAt(RowCol(1,1)) == 41);

Foreach over every (coord, tile) pair in the map

1 import std.algorithm : equal;
2 
3 auto grid = [
4   [ 00, 01, 02, ],
5   [ 10, 11, 12, ],
6 ];
7 auto myMap = OrthoMap!int(grid, 32, 64);
8 
9 
10 foreach(coord, tile ; myMap) assert(myMap.tileAt(coord) == tile);

Meta