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

import std.algorithm : equal;

auto grid = [
  [ 00, 01, 02, ],
  [ 10, 11, 12, ],
];
auto myMap = OrthoMap!int(grid, 32, 64);

int[] result;

foreach(tile ; myMap) result ~= tile;

assert(result.equal([ 00, 01, 02, 10, 11, 12 ]));

Use ref with foreach to modify tiles

auto grid = [
  [ 00, 01, 02, ],
  [ 10, 11, 12, ],
];
auto myMap = OrthoMap!int(grid, 32, 64);

foreach(ref tile ; myMap) tile += 30;

assert(myMap.tileAt(RowCol(1,1)) == 41);

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

import std.algorithm : equal;

auto grid = [
  [ 00, 01, 02, ],
  [ 10, 11, 12, ],
];
auto myMap = OrthoMap!int(grid, 32, 64);


foreach(coord, tile ; myMap) assert(myMap.tileAt(coord) == tile);

Meta