Skip to content

Latest commit

 

History

History
69 lines (37 loc) · 3.25 KB

Map2D.md

File metadata and controls

69 lines (37 loc) · 3.25 KB

Map2D

Create and render visual tiled maps which are laid out in a 2D spatial grid map data structure

Examples can be found here:

A Grid of Tiles

Tiled Maps

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 coordinates system

The Source of the Tile IDs

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.

RepeatingTilesProvider

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.

repeating-tiles-provider cheat-sheet

From Tile to 2D Coordinates

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).

map2d-tile-coords-util cheat-sheet

Map2DLayer

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.

Map2dLayer class diagram

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).

Map2dLayer update

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:

Map2dLayer update view area

The IMap2DTileRenderer is responsible for the display of the tiles.

CameraBasedVisibility

how it works: CameraBasedVisibility