Create and render visual tiled maps which are laid out in a 2D spatial grid map data structure
Examples can be found here:
- tiled-maps-basic-layer-tiles-renderer (vanilla)
- map2d-tile-sprites (react)
- map2d-tile-sprites-layer (react)
- map2d-camera-based-visibility (react)
All tiles are generally determined by a numerical (uint32
) ID.
For simplicity, it is assumed that the tiles are located in a 2D coordinate system.
The tile IDs are read out via the IMap2DTileDataProvider interface.
Tile IDs start at 1
and are unsigned integers, where 0
means there is no tile there.
The RepeatingTilesProvider is an easy to use tile data provider which repeats a 2D pattern of tile IDs endlessly. Very handy when you just want a constantly repeating background.
If you want you can limit the repeat to only horizontal or only vertical.
The Map2DTileCoordsUtil does the mapping from 2D world coordinates to tile coordinates.
the origin of the 2D coordinate system is assumed to be in the upper left corner (with the y-axis pointing down).
TODO the docs are a bit outdated, the IMap2DVisibilitor interface is a recently added feature
In a Map2DLayer, the world is divided into a static grid with tiles of equal size. Which tiles are displayed is determined by the view area (which is an AABB2) of the layer.
The layer does not render the tiles itself, it only manages which tiles are visible, which are created and which can be removed (because they are outside the view area).
Every time the view area is updated (by calling map2dLayer.update()
in combination with changes to the map2d layer properties), the IMap2DTileRenderer is informed about it using callbacks - these callbacks are always called in the same order:
The IMap2DTileRenderer is responsible for the display of the tiles.