Functions
Tilemap

Tilemap resources management for background layers. More...

Description

Functions

TLNAPI TLN_Tilemap TLN_CreateTilemap (int rows, int cols, TLN_Tile tiles, uint32_t bgcolor, TLN_Tileset tileset)
 Creates a new tilemap. More...
 
TLNAPI TLN_Tilemap TLN_LoadTilemap (const char *filename, const char *layername)
 Loads a tilemap layer from a Tiled .tmx file. More...
 
TLNAPI TLN_Tilemap TLN_CloneTilemap (TLN_Tilemap src)
 Creates a duplicate of the specified tilemap. More...
 
TLNAPI int TLN_GetTilemapRows (TLN_Tilemap tilemap)
 Returns the number of vertical tiles in the tilemap. More...
 
TLNAPI int TLN_GetTilemapCols (TLN_Tilemap tilemap)
 Returns the number of horizontal tiles in the tilemap. More...
 
TLNAPI TLN_Tileset TLN_GetTilemapTileset (TLN_Tilemap tilemap)
 Returns the optional associated tileset to the specified tilemap. More...
 
TLNAPI bool TLN_GetTilemapTile (TLN_Tilemap tilemap, int row, int col, TLN_Tile tile)
 Gets data of a single tile inside a tilemap. More...
 
TLNAPI bool TLN_SetTilemapTile (TLN_Tilemap tilemap, int row, int col, TLN_Tile tile)
 Sets a tile of a tilemap. More...
 
TLNAPI 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...
 
TLNAPI bool TLN_DeleteTilemap (TLN_Tilemap tilemap)
 Deletes the specified tilemap and frees memory. More...
 

Function Documentation

TLNAPI TLN_Tilemap TLN_CreateTilemap ( int  rows,
int  cols,
TLN_Tile  tiles,
uint32_t  bgcolor,
TLN_Tileset  tileset 
)
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
TLNAPI TLN_Tilemap TLN_LoadTilemap ( const char *  filename,
const char *  layername 
)
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
TLNAPI TLN_Tilemap TLN_CloneTilemap ( TLN_Tilemap  src)
Parameters
srcReference to the tilemap to clone
Returns
A reference to the newly cloned tilemap, or NULL if error
See also
TLN_LoadTilemap()
TLNAPI int TLN_GetTilemapRows ( TLN_Tilemap  tilemap)
Parameters
tilemapReference of the tilemap to get info
See also
TLN_GetTilemapCols()
TLNAPI int TLN_GetTilemapCols ( TLN_Tilemap  tilemap)
Parameters
tilemapReference of the tilemap to get info
See also
TLN_GetTilemapCols()
TLNAPI TLN_Tileset TLN_GetTilemapTileset ( TLN_Tilemap  tilemap)
Parameters
tilemapReference of the tilemap to get info
See also
TLN_CreateTilemap(), TLN_LoadTilemap()
TLNAPI bool TLN_GetTilemapTile ( TLN_Tilemap  tilemap,
int  row,
int  col,
TLN_Tile  tile 
)
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
TLNAPI bool TLN_SetTilemapTile ( TLN_Tilemap  tilemap,
int  row,
int  col,
TLN_Tile  tile 
)
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
Returns
true (success) or false (error)
TLNAPI bool TLN_CopyTiles ( TLN_Tilemap  src,
int  srcrow,
int  srccol,
int  rows,
int  cols,
TLN_Tilemap  dst,
int  dstrow,
int  dstcol 
)
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
TLNAPI bool TLN_DeleteTilemap ( TLN_Tilemap  tilemap)
Parameters
tilemapReference to the tilemap to delete
Remarks
Don't delete a tilemap currently attached to a layer!
See also
TLN_LoadTilemap(), TLN_CloneTilemap()