2.15.1
Functions
Tilemap

Tilemap resources management for background layers. More...

Description

Tilemap resources management for background layers.

Functions

TLN_Tilemap TLN_CreateTilemap (int rows, int cols, TLN_Tile tiles, uint32_t bgcolor, TLN_Tileset tileset)
 Creates a new tilemap. More...
 
TLN_Tilemap TLN_LoadTilemap (const char *filename, const char *layername)
 Loads a tilemap layer from a Tiled .tmx file. More...
 
TLN_Tilemap TLN_CloneTilemap (TLN_Tilemap src)
 Creates a duplicate of the specified tilemap. More...
 
int TLN_GetTilemapRows (TLN_Tilemap tilemap)
 Returns the number of vertical tiles in the tilemap. More...
 
int TLN_GetTilemapCols (TLN_Tilemap tilemap)
 Returns the number of horizontal tiles in the tilemap. More...
 
bool TLN_SetTilemapTileset (TLN_Tilemap tilemap, TLN_Tileset tileset)
 Sets default tileset to specified tilemap. More...
 
TLN_Tileset TLN_GetTilemapTileset (TLN_Tilemap tilemap)
 Returns the optional associated tileset to the specified tilemap. More...
 
bool TLN_SetTilemapTileset2 (TLN_Tilemap tilemap, TLN_Tileset tileset, int index)
 Sets default tileset to specified tilemap. More...
 
TLN_Tileset TLN_GetTilemapTileset2 (TLN_Tilemap tilemap, int index)
 Returns the nth tileset associated tileset to the specified tilemap. More...
 
bool TLN_GetTilemapTile (TLN_Tilemap tilemap, int row, int col, TLN_Tile tile)
 Gets data of a single tile inside a tilemap. More...
 
bool TLN_SetTilemapTile (TLN_Tilemap tilemap, int row, int col, TLN_Tile tile)
 Sets a tile of a tilemap. More...
 
bool TLN_CopyTiles (TLN_Tilemap src, int srcrow, int srccol, int rows, int cols, TLN_Tilemap dst, int dstrow, int dstcol)
 Copies blocks of tiles between two tilemaps. More...
 
TLN_Tile TLN_GetTilemapTiles (TLN_Tilemap tilemap, int row, int col)
 Returns pointer to internal tilemap data data. More...
 
bool TLN_DeleteTilemap (TLN_Tilemap tilemap)
 Deletes the specified tilemap and frees memory. More...
 

Function Documentation

◆ TLN_CreateTilemap()

TLN_Tilemap TLN_CreateTilemap ( int  rows,
int  cols,
TLN_Tile  tiles,
uint32_t  bgcolor,
TLN_Tileset  tileset 
)

Creates a new tilemap.

Parameters
rowsNumber of rows (vertical dimension)
colsNumber of cols (horizontal dimension)
tilesArray of tiles with data (see struct Tile)
bgcolorBackground color value (RGB32 packed)
tilesetOptional reference to associated tileset, can be NULL
Returns
Reference to the created tilemap, or NULL if error
Remarks
Make sure that the tiles[] array is has at least rows*cols items or application may crash
See also
TLN_DeleteTilemap(), struct Tile

◆ TLN_LoadTilemap()

TLN_Tilemap TLN_LoadTilemap ( const char *  filename,
const char *  layername 
)

Loads a tilemap layer from a Tiled .tmx file.

Parameters
filenameTMX file with the tilemap
layernameOptional name of the layer inside the tmx file to load. NULL to load the first layer
Returns
Reference to the newly loaded tilemap or NULL if error
Remarks
A tmx map file from Tiled can contain one or more layers, each with its own name. TLN_LoadTilemap() doesn't load a full tmx file, only the specified layer. The associated external tileset (TSX file) is also loaded and associated to the tilemap

◆ TLN_CloneTilemap()

TLN_Tilemap TLN_CloneTilemap ( TLN_Tilemap  src)

Creates a duplicate of the specified tilemap.

Parameters
srcReference to the tilemap to clone
Returns
A reference to the newly cloned tilemap, or NULL if error
See also
TLN_LoadTilemap()

◆ TLN_GetTilemapRows()

int TLN_GetTilemapRows ( TLN_Tilemap  tilemap)

Returns the number of vertical tiles in the tilemap.

Parameters
tilemapReference of the tilemap to get info
See also
TLN_GetTilemapCols()

◆ TLN_GetTilemapCols()

int TLN_GetTilemapCols ( TLN_Tilemap  tilemap)

Returns the number of horizontal tiles in the tilemap.

Parameters
tilemapReference of the tilemap to get info
See also
TLN_GetTilemapCols()

◆ TLN_SetTilemapTileset()

bool TLN_SetTilemapTileset ( TLN_Tilemap  tilemap,
TLN_Tileset  tileset 
)

Sets default tileset to specified tilemap.

Parameters
tilemapReference to the tilemap to modify
tilesetReference to the tileset being assigned
See also
TLN_GetTilemapTileset()

◆ TLN_GetTilemapTileset()

TLN_Tileset TLN_GetTilemapTileset ( TLN_Tilemap  tilemap)

Returns the optional associated tileset to the specified tilemap.

Parameters
tilemapReference of the tilemap to get info
See also
TLN_CreateTilemap(), TLN_LoadTilemap()

◆ TLN_SetTilemapTileset2()

bool TLN_SetTilemapTileset2 ( TLN_Tilemap  tilemap,
TLN_Tileset  tileset,
int  index 
)

Sets default tileset to specified tilemap.

Parameters
tilemapReference to the tilemap to modify
tilesetReference to the tileset being assigned
indexIndex of tileset to set (0 - 7)
See also
TLN_GetTilemapTileset()

◆ TLN_GetTilemapTileset2()

TLN_Tileset TLN_GetTilemapTileset2 ( TLN_Tilemap  tilemap,
int  index 
)

Returns the nth tileset associated tileset to the specified tilemap.

Parameters
tilemapReference of the tilemap to get info
indexTileset index (0 - 7)
See also
TLN_CreateTilemap(), TLN_LoadTilemap()

◆ TLN_GetTilemapTile()

bool TLN_GetTilemapTile ( TLN_Tilemap  tilemap,
int  row,
int  col,
TLN_Tile  tile 
)

Gets data of a single tile inside a tilemap.

Parameters
tilemapReference of the tilemap to get the tile
rowVertical location of the tile (0 <= row < rows)
colHorizontal location of the tile (0 <= col < cols)
tileReference to an application-allocated struct Tile that will get the data

◆ TLN_SetTilemapTile()

bool TLN_SetTilemapTile ( TLN_Tilemap  tilemap,
int  row,
int  col,
TLN_Tile  tile 
)

Sets a tile of a tilemap.

Parameters
tilemapReference to the tilemap
rowRow (vertical position) of the tile [0 - num_rows - 1]
colColumn (horizontal position) of the tile [0 - num_cols - 1]
tileReference to the tile to set, or NULL to set an empty tile
Returns
true (success) or false (error)

◆ TLN_CopyTiles()

bool TLN_CopyTiles ( TLN_Tilemap  src,
int  srcrow,
int  srccol,
int  rows,
int  cols,
TLN_Tilemap  dst,
int  dstrow,
int  dstcol 
)

Copies blocks of tiles between two tilemaps.

Parameters
srcReference to the source tilemap
srcrowStarting row (vertical position) inside the source tilemap
srccolStarting column (horizontal position) inside the source tilemap
rowsNumber of rows to copy
colsNumber of columns to copy
dstReference to the target tilemap
dstrowStarting row (vertical position) inside the target tilemap
dstcolStarting column (horizontal position) inside the target tilemap
Remarks
Use this function to implement tile streaming

◆ TLN_GetTilemapTiles()

TLN_Tile TLN_GetTilemapTiles ( TLN_Tilemap  tilemap,
int  row,
int  col 
)

Returns pointer to internal tilemap data data.

Parameters
tilemapTilemap being queried
rowRow index
colColumn index
Returns
pointer to corresponding TLN_Tile object or NULL if error
Remarks
Having direct access to internal memory is convenient for performance reasons when lots of tiles must be updated at runtime, but wrong manipulation can lead to memory corruption or crashes. Use with caution!

◆ TLN_DeleteTilemap()

bool TLN_DeleteTilemap ( TLN_Tilemap  tilemap)

Deletes the specified tilemap and frees memory.

Parameters
tilemapReference to the tilemap to delete
Remarks
Don't delete a tilemap currently attached to a layer!
See also
TLN_LoadTilemap(), TLN_CloneTilemap()