CRM64Pro GDK v0.13.0
A free cross-platform game development kit built on top of SDL 3.0
Loading...
Searching...
No Matches

Description

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 managementCreate, load, save and manage complete tilesets
Tile accessAccess individual tiles by index within a tileset
Image integrationGet Image ID to access the underlying Image object (export, alpha modulation, etc.)

Storage layer

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

Classes

class  CRM64Pro::Tile
 Tile Object class. More...
class  CRM64Pro::TileMgr
 Tile Manager class. More...

Functions

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.
TileCRM64Pro::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.

Function Documentation

◆ info() [1/2]

Sint32 CRM64Pro::Tile::info ( Sint32 iMode = 0)

Request Tile object information.

Writes information to the default log.

Parameters
iModeunused 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
sNamea 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
idImageImage id.
iOwnership0 (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
iTSMode0 to disable tileset mode, any other value to enable it.
iXinteger with the tileset offset X.
iYinteger 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
iXan integer pointer filled in with tileset offset X. If nullptr is passed, the method ignores the retrieving of this value.
iYan 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
fXtile X position.
fYtile 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
fXa float pointer filled in with X tile position. If nullptr is passed, the method ignores the retrieving of this value.
fYa 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
iXan 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.
iYan 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
iTStile id from the current tileset. From 1 to number of tiles.
idResa 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
iTStile id from the current tileset. From 1 to number of tiles.
dAngleangle in degrees for rotation.
poCenterSDL_FPoint pointer indicating rotation center. Default nullptr rotates around rDst.w/2 and rDst.h/2.
rf"SDL_FlipMode" value for flipping actions.
idResa 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
sFileCDCstring 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
idCDCCDC id.
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
sNameThe tile name (e.g. 'myTile'). Must be unique, max 64 characters.
iVersionTile 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
idTile0 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
idTileTile id.
sNameThe 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
idTileTile id.
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
idTileparent 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
sFileCDCstring containing [directory]+filename. Directory separators '\' and '/' are supported.
sNamestring 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
idCDCCDC id.
sNamestring 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
idCDCCDC id.
sNamestring 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.