Struct 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
Name | Description |
---|---|
this
|
Construct an orthogonal tilemap from a rectangular (non-jagged) grid of tiles .
|
Fields
Name | Type | Description |
---|---|---|
grid
|
RectGrid!(Tile[][]) |
The underlying tile grid structure, surfaced with alias this.
|
Methods
Name | Description |
---|---|
tileCenter
|
Get the pixel offset of the center of the tile at the given coord .
|
tileHeight
|
Height of each tile in pixels |
tileOffset
|
Get the pixel offset of the top-left corner of the tile at the given coord .
|
tileWidth
|
Width of each tile in pixels |
Templates
Name | Description |
---|---|
containsPoint
|
True if the pixel position is within the map bounds. |
coordAtPoint
|
Get the grid location corresponding to a given pixel coordinate.
|
tileAtPoint
|
Get the tile at a given pixel position on the map. Throws if out of bounds. |
Example
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 ]));
Example
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);
Example
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);
Authors
Copyright
Copyright © 2015, Ryan Roden-Corrent