Tile Manager and Tile objects for handling tiles and tilesets [v25.12.0].
Overview
The Tile module provides management for tiles and tilesets. Tiles are smaller images of uniform, rectangular size that can be combined into larger "image maps", allowing the creation of huge game maps while saving significant memory. A collection of tiles is called a tileset, where tile dimensions are defined by X and Y offsets.
Tileset image with 12 tiles
Key features
-
Memory efficient: Combine small uniform tiles into large game maps
-
Flexible tile size: Configurable tile dimensions via X and Y offsets
-
Image access: Direct access to underlying Image object for advanced manipulation
-
CDC storage: Load and save tilesets using CDC v1.x specification
-
Cloning support: Automatic child tile creation for shared resources
Tile operations
| Tileset management | Create, load, save and manage complete tilesets |
| Tile access | Access individual tiles by index within a tileset |
| Image integration | Get Image ID to access the underlying Image object (export, alpha modulation, etc.) |
Storage layer
| Format | CDC v1.x specification |
| load() | Load tileset from CDC archive |
| save() | Save tileset to CDC archive |
Manager type
This is an advanced "cloning" manager: when loading a tile from a CDC file that is already loaded or created (using the name as the key), it will create a new child tile. Child tiles share base data with the parent while allowing independent modifications.
Best practices
-
Leverage the cloning feature to efficiently share tileset resources across multiple game objects
-
Access the underlying Image object via its ID when you need to export or modify tile properties
-
Use CDC archives for organized storage of multiple tilesets
-
Consider tile dimensions carefully: smaller tiles offer more flexibility but require more indices
-
Access the manager exclusively through Main::ITileMgr()
- Note
- The Tile Manager is a singleton, automatically created once Main is instantiated. You can get a reference to this manager using Main::ITileMgr() method.
The Tile Manager is automatically released when Main::Terminate() is called. At this time, any resource still loaded will be released, avoiding resource leaks.
|
| Sint32 | CRM64Pro::Tile::info (Sint32 iMode=0) |
| | Request Tile object information.
|
| Sint32 | CRM64Pro::Tile::getName (string &sName) |
| | Get the name.
|
| Uint32 | CRM64Pro::Tile::getID () |
| | Get the ID.
|
| Sint32 | CRM64Pro::Tile::assignImage (Sint32 idImage, Sint32 iOwnership=0) |
| | Assign an Image to this tile.
|
| Sint32 | CRM64Pro::Tile::getImage () |
| | Get the assigned Image of this tile.
|
| Sint32 | CRM64Pro::Tile::setOffset (Sint32 iTSMode, Sint32 iX, Sint32 iY) |
| | Set the tile offsets for creating a tileset (also enable/disable tileset mode).
|
| Sint32 | CRM64Pro::Tile::getOffset (Sint32 *iX, Sint32 *iY) |
| | Get the tile offsets (tileset attributes).
|
| Sint32 | CRM64Pro::Tile::setPosition (float fX, float fY) |
| | Set the tile position.
|
| Sint32 | CRM64Pro::Tile::getPosition (float *fX, float *fY) |
| | Get the tile position.
|
| Sint32 | CRM64Pro::Tile::getNumTiles (Sint32 *iX=nullptr, Sint32 *iY=nullptr) |
| | Get the number of tiles.
|
| Sint32 | CRM64Pro::Tile::render (Sint32 iTS=1, Sint32 idRes=0) |
| | Render the tile.
|
| Sint32 | CRM64Pro::Tile::renderEx (Sint32 iTS=1, const double dAngle=0.0, const SDL_FPoint *poCenter=nullptr, const SDL_FlipMode rf=SDL_FLIP_NONE, Sint32 idRes=0) |
| | Render the tile with extended attributes.
|
| Sint32 | CRM64Pro::Tile::save (const string &sFileCDC) |
| | Save the tile to a CDC file.
|
| Sint32 | CRM64Pro::Tile::save (Sint32 idCDC) |
| | Save the tile to a CDC file.
|
| Sint32 | CRM64Pro::TileMgr::info (Sint32 iMode=0) |
| | Request Tile Manager information.
|
| Sint32 | CRM64Pro::TileMgr::create (const string &sName, Uint32 iVersion=10) |
| | Create a new tile.
|
| Sint32 | CRM64Pro::TileMgr::close (Sint32 idTile) |
| | Close and destroy a tile.
|
| Sint32 | CRM64Pro::TileMgr::getNum () const |
| | Get number of loaded objects.
|
| Sint32 | CRM64Pro::TileMgr::setName (Sint32 idTile, const string &sName) |
| | Change the object name.
|
| Tile * | CRM64Pro::TileMgr::get (Sint32 idTile) |
| | Get a pointer to the tile using its handler.
|
| Sint32 | CRM64Pro::TileMgr::child (Sint32 idTile) |
| | Create a child tile dependent on the provided one (the parent).
|
| Sint32 | CRM64Pro::TileMgr::load (const string &sFileCDC, const string &sName) |
| | Load a tile stored in a CDC file.
|
| Sint32 | CRM64Pro::TileMgr::load (const Sint32 idCDC, const string &sName) |
| | Load a tile stored in a CDC file.
|
| Sint32 | CRM64Pro::TileMgr::remove (const Sint32 idCDC, const string &sName) |
| | Remove a tile stored in a CDC file.
|
◆ info() [1/2]
| Sint32 CRM64Pro::Tile::info |
( |
Sint32 | iMode = 0 | ) |
|
Request Tile object information.
Writes information to the default log.
- Parameters
-
| iMode | unused for the time being. |
- Returns
- 0 on success, or a negative error code on failure.
◆ getName()
| Sint32 CRM64Pro::Tile::getName |
( |
string & | sName | ) |
|
Get the name.
- Parameters
-
| sName | a string containing the tile name. |
- Returns
- 0 on success, or a negative error code on failure.
◆ getID()
| Uint32 CRM64Pro::Tile::getID |
( |
| ) |
|
Get the ID.
- Returns
- Object ID.
◆ assignImage()
| Sint32 CRM64Pro::Tile::assignImage |
( |
Sint32 | idImage, |
|
|
Sint32 | iOwnership = 0 ) |
Assign an Image to this tile.
Used for loading an Image when the tile is created with TileMgr::create().
- Parameters
-
| idImage | Image id. |
| iOwnership | 0 (default) creates a copy; any other value takes ownership (image cannot be owned by another item). |
- Returns
- 0 on success, or a negative error code on failure.
- Note
- Image name is internally modified (prefixed with '#' + internal code + tile name). Re-assigning closes the old image.
◆ getImage()
| Sint32 CRM64Pro::Tile::getImage |
( |
| ) |
|
Get the assigned Image of this tile.
- Returns
- greater than 0 on success, or a negative error code on failure.
◆ setOffset()
| Sint32 CRM64Pro::Tile::setOffset |
( |
Sint32 | iTSMode, |
|
|
Sint32 | iX, |
|
|
Sint32 | iY ) |
Set the tile offsets for creating a tileset (also enable/disable tileset mode).
In tileset mode, the image is divided by iX on X axis and by iY on Y axis. Non-exact divisions are allowed; remainder parts are unused.
- Parameters
-
| iTSMode | 0 to disable tileset mode, any other value to enable it. |
| iX | integer with the tileset offset X. |
| iY | integer with the tileset offset Y. |
- Returns
- 0 on success, or a negative error code on failure.
◆ getOffset()
| Sint32 CRM64Pro::Tile::getOffset |
( |
Sint32 * | iX, |
|
|
Sint32 * | iY ) |
Get the tile offsets (tileset attributes).
- Parameters
-
| iX | an integer pointer filled in with tileset offset X. If nullptr is passed, the method ignores the retrieving of this value. |
| iY | an integer pointer filled in with tileset offset Y. If nullptr is passed, the method ignores the retrieving of this value. |
- Returns
- 0 tileset mode is not enabled or 1 when it is enabled.
◆ setPosition()
| Sint32 CRM64Pro::Tile::setPosition |
( |
float | fX, |
|
|
float | fY ) |
Set the tile position.
- Parameters
-
| fX | tile X position. |
| fY | tile Y position. |
- Returns
- 0 on success, or a negative error code on failure.
◆ getPosition()
| Sint32 CRM64Pro::Tile::getPosition |
( |
float * | fX, |
|
|
float * | fY ) |
Get the tile position.
- Parameters
-
| fX | a float pointer filled in with X tile position. If nullptr is passed, the method ignores the retrieving of this value. |
| fY | a float pointer filled in with Y tile position. If nullptr is passed, the method ignores the retrieving of this value. |
- Returns
- 0 on success, or a negative error code on failure.
◆ getNumTiles()
| Sint32 CRM64Pro::Tile::getNumTiles |
( |
Sint32 * | iX = nullptr, |
|
|
Sint32 * | iY = nullptr ) |
Get the number of tiles.
- Parameters
-
| iX | an integer pointer filled in with the tiles on the X axis. If nullptr is passed (default value), the method ignores the retrieving of this value. |
| iY | an integer pointer filled in with the tiles on the Y axis. If nullptr is passed (default value), the method ignores the retrieving of this value. |
- Returns
- The total number of tiles [0, n).
◆ render()
| Sint32 CRM64Pro::Tile::render |
( |
Sint32 | iTS = 1, |
|
|
Sint32 | idRes = 0 ) |
Render the tile.
- Parameters
-
| iTS | tile id from the current tileset. From 1 to number of tiles. |
| idRes | a valid screen or image handle. Default uses the default screen. |
- Returns
- 0 on success, or a negative error code on failure.
◆ renderEx()
| Sint32 CRM64Pro::Tile::renderEx |
( |
Sint32 | iTS = 1, |
|
|
const double | dAngle = 0.0, |
|
|
const SDL_FPoint * | poCenter = nullptr, |
|
|
const SDL_FlipMode | rf = SDL_FLIP_NONE, |
|
|
Sint32 | idRes = 0 ) |
Render the tile with extended attributes.
- Parameters
-
| iTS | tile id from the current tileset. From 1 to number of tiles. |
| dAngle | angle in degrees for rotation. |
| poCenter | SDL_FPoint pointer indicating rotation center. Default nullptr rotates around rDst.w/2 and rDst.h/2. |
| rf | "SDL_FlipMode" value for flipping actions. |
| idRes | a valid screen or image handle. Default uses the default screen. |
- Returns
- 0 on success, or a negative error code on failure.
◆ save() [1/2]
| Sint32 CRM64Pro::Tile::save |
( |
const string & | sFileCDC | ) |
|
Save the tile to a CDC file.
The associated image will also be saved to the same CDC file.
- Parameters
-
| sFileCDC | string containing [directory]+filename+[extension]. Directory separators '\' and '/' are supported. |
- Returns
- 0 or greater on success or a negative error code on failure.
- Note
- Existing tile is overwritten. Cannot save child tiles.
◆ save() [2/2]
| Sint32 CRM64Pro::Tile::save |
( |
Sint32 | idCDC | ) |
|
Save the tile to a CDC file.
The associated image will also be saved to the same CDC file.
- Parameters
-
- Returns
- 0 or greater on success or a negative error code on failure.
- Note
- Existing tile is overwritten. If a child, calls parent's save method.
◆ info() [2/2]
| Sint32 CRM64Pro::TileMgr::info |
( |
Sint32 | iMode = 0 | ) |
|
Request Tile Manager information.
Writes information to the default log.
- Parameters
-
| iMode | -1 for Manager info only. 0 (default) for Manager and all Objects. A positive Tile id for Manager and that specific Tile. |
- Returns
- 0 on success, or a negative error code on failure.
◆ create()
| Sint32 CRM64Pro::TileMgr::create |
( |
const string & | sName, |
|
|
Uint32 | iVersion = 10 ) |
Create a new tile.
Creates an empty tile (no image). Use Tile::assignImage() to assign an image.
- Parameters
-
| sName | The tile name (e.g. 'myTile'). Must be unique, max 64 characters. |
| iVersion | Tile version. 10 means v1.0 (only version supported). Default v1.0. |
- Returns
- greater than 0 on success (the Tile id) or a negative error code on failure.
- Note
- Returns error if name already exists.
◆ close()
| Sint32 CRM64Pro::TileMgr::close |
( |
Sint32 | idTile | ) |
|
Close and destroy a tile.
- Parameters
-
| idTile | 0 for closing all tiles, or specific Tile id. Stand-alone and child tiles can be closed; parent tiles cannot while they have children. |
- Returns
- 0 on success, or a negative error code on failure.
- Note
- Unclosed tiles are automatically closed when the GDK terminates.
◆ getNum()
| Sint32 CRM64Pro::TileMgr::getNum |
( |
| ) |
const |
Get number of loaded objects.
- Returns
- the number of tiles.
◆ setName()
| Sint32 CRM64Pro::TileMgr::setName |
( |
Sint32 | idTile, |
|
|
const string & | sName ) |
Change the object name.
- Parameters
-
| idTile | Tile id. |
| sName | The tile name (e.g. 'myTile'). Must be unique, max 64 characters. |
- Returns
- 0 on success, or a negative error code on failure.
- Note
- Image name is internally modified (prefixed with '#' + internal code + tile name).
◆ get()
| Tile * CRM64Pro::TileMgr::get |
( |
Sint32 | idTile | ) |
|
Get a pointer to the tile using its handler.
- Parameters
-
- Returns
- nullptr if tile not found.
-
A pointer to the tile object.
◆ child()
| Sint32 CRM64Pro::TileMgr::child |
( |
Sint32 | idTile | ) |
|
Create a child tile dependent on the provided one (the parent).
A child tile uses parent's attributes and creates a child image for different attributes.
- Parameters
-
| idTile | parent Tile id. If the provided tile is a child, the request is redirected to its parent. |
- Returns
- greater than 0 on success (the Tile id) or a negative error code on failure.
- Note
- The child uses the parent's name.
◆ load() [1/2]
| Sint32 CRM64Pro::TileMgr::load |
( |
const string & | sFileCDC, |
|
|
const string & | sName ) |
Load a tile stored in a CDC file.
- Parameters
-
| sFileCDC | string containing [directory]+filename. Directory separators '\' and '/' are supported. |
| sName | string with the tile name (max 64 characters). If already exists, creates a child instead. |
- Returns
- 0 or greater on success (the Tile id) or a negative error code on failure.
◆ load() [2/2]
| Sint32 CRM64Pro::TileMgr::load |
( |
const Sint32 | idCDC, |
|
|
const string & | sName ) |
Load a tile stored in a CDC file.
- Parameters
-
| idCDC | CDC id. |
| sName | string with the tile name (max 64 characters). If already exists, creates a child instead. |
- Returns
- greater than 0 on success (the Tile id) or a negative error code on failure.
◆ remove()
| Sint32 CRM64Pro::TileMgr::remove |
( |
const Sint32 | idCDC, |
|
|
const string & | sName ) |
Remove a tile stored in a CDC file.
- Parameters
-
| idCDC | CDC id. |
| sName | string with the tile name (maximum size of 64 characters). |
- Returns
- greater than 0 on success, or a negative error code on failure.
- Note
- The tile must be closed before trying to remove it from the CDC.