| CRM64Pro GDK v0.18.0 A free cross-platform game development kit built on top of SDL 3.0

Loading...
Searching...
No Matches
Scene Layer Tile
Scene modules » Scene Layer

## Description

TileLayer class for tile-based map layers.

SceneLayerTile manages a 2D grid of tile indices (Global IDs) that reference tiles from loaded TileSets. Supports variable cell sizes and provides methods for tile manipulation and rendering.

## Classes
class | CRM64Pro::SceneLayerTile
| TileLayer class for tile-based map layers. More...

## Functions
eSceneLayerType | CRM64Pro::SceneLayerTile::getType () const override
| Get the layer type.
Sint32 | CRM64Pro::SceneLayerTile::getCellWidth () const
| Get cell width.
Sint32 | CRM64Pro::SceneLayerTile::getCellHeight () const
| Get cell height.
Sint32 | CRM64Pro::SceneLayerTile::getWidth () const
| Get map width.
Sint32 | CRM64Pro::SceneLayerTile::getHeight () const
| Get map height.
float | CRM64Pro::SceneLayerTile::getTotalWidth () const override
| Get layer total width in pixels.
float | CRM64Pro::SceneLayerTile::getTotalHeight () const override
| Get layer total height in pixels.
bool | CRM64Pro::SceneLayerTile::setCellWidth (Sint32 iSize)
| Set cell width.
bool | CRM64Pro::SceneLayerTile::setCellHeight (Sint32 iSize)
| Set cell height.
bool | CRM64Pro::SceneLayerTile::allocateCells (Sint32 iHeight, Sint32 iWidth, Uint32 iValue=0)
| Allocate the 2D array for the cells.
bool | CRM64Pro::SceneLayerTile::freeCells ()
| Free the 2D array of cells.
bool | CRM64Pro::SceneLayerTile::setCellValue (Sint32 iY, Sint32 iX, Uint32 iValue)
| Set arbitrary values on 2D array of cells.
bool | CRM64Pro::SceneLayerTile::clone (SceneLayerTile *pDest)
| Copy the current values of the 2D array iCellMap to the given TileLayer.
bool | CRM64Pro::SceneLayerTile::isValid () const
| Map validation.
Sint32 | CRM64Pro::SceneLayerTile::info (Sint8 iTilesetReady, eLogLevel eLL)
| Request TileLayer object information.
VisibleRange | CRM64Pro::SceneLayerTile::calculateVisibleRange (const SDL_Rect &rViewport, float fOffsetX, float fOffsetY)
| Calculate visible range of tiles for a given viewport and offset.
Sint32 | CRM64Pro::SceneLayerTile::update (Scene *pEngine, SceneLayerContext &rContext) override
| Update tile layer logic.
Sint32 | CRM64Pro::SceneLayerTile::render (Scene *pEngine, SceneLayerContext &rContext) override
| Render tile layer content.
Sint32 | CRM64Pro::SceneLayerTile::cellRender (Sint32 iCellX, Sint32 iCellY, float fDstX, float fDstY, Sint32 iAlpha, Sint32 idTileset, Uint32 idTile, Sint32 idRes)
| Render a cell.
Sint32 | CRM64Pro::Scene::createTileSet (Sint32 idRes, Sint32 globalID=-1)
| Create a TileSet from a memory resource (Image or Tile).
Sint32 | CRM64Pro::Scene::createTileSet (const string &sCDCFile, const string &sResourceName, Sint32 globalID=-1)
| Create a TileSet from a CDC archive resource.
Sint32 | CRM64Pro::Scene::createTileSetFromFile (const string &sPath, Sint32 globalID=-1, Sint32 iTileWidth=-1, Sint32 iTileHeight=-1)
| Create a TileSet from a file on disk.
Sint32 | CRM64Pro::Scene::setTileAnimation (Uint32 iTileGID, const vector< Uint32 > &vFrameGID, const vector< Sint32 > &vDuration)
| Set a TileSet animation for a tile.
Sint32 | CRM64Pro::Scene::clearTileAnimation (Uint32 iTileGID)
| Clear a TileSet animation from a tile.
bool | CRM64Pro::Scene::closeTileSet (Sint32 iTN)
| Close and destroy a given TileSet.
Sint32 | CRM64Pro::Scene::getTileResourceID (Sint32 iTN)
| Resolve a Global Tile ID to its internal CRM64Pro Tile Resource ID.
eSceneTileSetType | CRM64Pro::Scene::getTileSetType (Sint32 iTN)
| Get the TileSet type.
bool | CRM64Pro::Scene::getTileSetSource (Sint32 iTN, eSceneStorageMode &eMode, string &sPath, string &sFilename)
| Get the storage metadata for a TileSet.
bool | CRM64Pro::Scene::setTileSetSource (Sint32 iTN, eSceneStorageMode eMode, const string &sPath, const string &sFilename)
| Set the storage metadata for a TileSet.

## Function Documentation

## ◆ getType()

eSceneLayerType CRM64Pro::SceneLayerTile::getType | ( |  | ) | const
| override virtual

Get the layer type.

Returns
  SLT_TILE.

Implements CRM64Pro::SceneLayer.

## ◆ getCellWidth()

Sint32 CRM64Pro::SceneLayerTile::getCellWidth | ( |  | ) | const

Get cell width.

Returns
  integer with the cell width (in pixels).

## ◆ getCellHeight()

Sint32 CRM64Pro::SceneLayerTile::getCellHeight | ( |  | ) | const

Get cell height.

Returns
  integer with the cell height (in pixels).

## ◆ getWidth()

Sint32 CRM64Pro::SceneLayerTile::getWidth | ( |  | ) | const

Get map width.

Returns
  width of this map (in number of tiles).

## ◆ getHeight()

Sint32 CRM64Pro::SceneLayerTile::getHeight | ( |  | ) | const

Get map height.

Returns
  height of this map (in number of tiles).

## ◆ getTotalWidth()

float CRM64Pro::SceneLayerTile::getTotalWidth | ( |  | ) | const
| override virtual

Get layer total width in pixels.

Returns
  Width = cell width * map width.

Reimplemented from CRM64Pro::SceneLayer.

## ◆ getTotalHeight()

float CRM64Pro::SceneLayerTile::getTotalHeight | ( |  | ) | const
| override virtual

Get layer total height in pixels.

Returns
  Height = cell height * map height.

Reimplemented from CRM64Pro::SceneLayer.

## ◆ setCellWidth()

bool CRM64Pro::SceneLayerTile::setCellWidth | ( | Sint32 | iSize | ) |

Set cell width.

Parameters

  iSize | integer with cell width (in pixels).

Returns
  true on success, or false on failure.

## ◆ setCellHeight()

bool CRM64Pro::SceneLayerTile::setCellHeight | ( | Sint32 | iSize | ) |

Set cell height.

Parameters

  iSize | integer with cell height (in pixels).

Returns
  true on success, or false on failure.

## ◆ allocateCells()

bool CRM64Pro::SceneLayerTile::allocateCells | ( | Sint32 | iHeight,
|  | Sint32 | iWidth,
|  | Uint32 | iValue = 0 )

Allocate the 2D array for the cells.

Each element on this 2D array is a cell.

Parameters

  iHeight | Selected height of your map.
  iWidth | Selected width of your map.
  iValue | Default value to be assigned on each cell.

Returns
  true on success, or false on failure.

## ◆ freeCells()

bool CRM64Pro::SceneLayerTile::freeCells | ( |  | ) |

Free the 2D array of cells.

Returns
  true on success, or false on failure.

## ◆ setCellValue()

bool CRM64Pro::SceneLayerTile::setCellValue | ( | Sint32 | iY,
|  | Sint32 | iX,
|  | Uint32 | iValue )

Set arbitrary values on 2D array of cells.

It is mainly used for creating maps in a manual way.

Parameters

  iY | Selected Y position. Use -1 to affect all rows (Y axis).
  iX | Selected X position. Use -1 to affect all columns (X axis).

Note
  Sentinel behavior: y=-1,x=-1 fills the whole map; y=-1,x>=0 fills one column; y>=0,x=-1 fills one row.

Parameters

  iValue | The value to be set on the given position.

Returns
  true on success, or false on failure.

## ◆ clone()

bool CRM64Pro::SceneLayerTile::clone | ( | SceneLayerTile * | pDest | ) |

Copy the current values of the 2D array iCellMap to the given TileLayer.

The destination must have identical attributes (width and height). If the destination has not an iCellMap, we will create one identical to the source

Parameters

  pDest | Pointer to destination SceneLayerTile or derived object.

Returns
  true on success, or false on failure.

## ◆ isValid()

bool CRM64Pro::SceneLayerTile::isValid | ( |  | ) | const

Map validation.

Validates iCellMap 2D array: checks tile layer width/height, and checks cell width/height.

Returns
  true on success, or false on failure.

## ◆ info()

Sint32 CRM64Pro::SceneLayerTile::info | ( | Sint8 | iTilesetReady,
|  | eLogLevel | eLL )

Request TileLayer object information.

Writes information to the default log.

Parameters

  iTilesetReady | -1 do not display anything, 0 it is not ready and 1 it is ready.
  eLL | importance of the message. Check ::eLogLevel enum for further information.

Returns
  0 on success, or a negative error code on failure.

## ◆ calculateVisibleRange()

SceneLayerTile::VisibleRange CRM64Pro::SceneLayerTile::calculateVisibleRange | ( | const SDL_Rect & | rViewport,
|  | float | fOffsetX,
|  | float | fOffsetY )

Calculate visible range of tiles for a given viewport and offset.

Parameters

  rViewport | Viewport rectangle.
  fOffsetX | Layer X offset.
  fOffsetY | Layer Y offset.

Returns
  A VisibleRange struct containing start/end indices and pixel offsets.

## ◆ update()

Sint32 CRM64Pro::SceneLayerTile::update | ( | Scene * | pEngine,
|  | SceneLayerContext & | rContext )
| override protected virtual

Update tile layer logic.

Parameters

  pEngine | Pointer to the Scene instance.
  rContext | Layer context structure containing update state.

Returns
  0 on success, or a negative error code on failure.

Implements CRM64Pro::SceneLayer.

## ◆ render()

Sint32 CRM64Pro::SceneLayerTile::render | ( | Scene * | pEngine,
|  | SceneLayerContext & | rContext )
| override protected virtual

Render tile layer content.

Parameters

  pEngine | Pointer to the Scene instance.
  rContext | Layer context structure containing render state.

Returns
  0 on success, or a negative error code on failure.

Implements CRM64Pro::SceneLayer.

## ◆ cellRender()

Sint32 CRM64Pro::SceneLayerTile::cellRender | ( | Sint32 | iCellX,
|  | Sint32 | iCellY,
|  | float | fDstX,
|  | float | fDstY,
|  | Sint32 | iAlpha,
|  | Sint32 | idTileset,
|  | Uint32 | idTile,
|  | Sint32 | idRes )

Render a cell.

Parameters

  iCellX | Cell X coordinate to be rendered.
  iCellY | Cell y coordinate to be rendered.
  fDstX | Destination surface X coordinate to start to render in case you wish to.
  fDstY | Destination surface Y coordinate to start to render in case you wish to.
  iAlpha | Alpha modulation for this layer. This value overwrites the own tileset alpha modulation.
  idTileset | tileset id.
  idTile | which tile inside the tileset must be rendered.
  idRes | a valid screen or image handle used as rendering target.

Returns
  0 on success, or a negative error code on failure.

Note
  Tiles with different size to the underlying cells is supported: larger tiles will extend at the top and right.

## ◆ createTileSet() [1/2]

Sint32 CRM64Pro::Scene::createTileSet | ( | Sint32 | idRes,
|  | Sint32 | globalID = -1 )

Create a TileSet from a memory resource (Image or Tile).

Parameters

  idRes | ID of the resource (Image or Tile) loaded in memory.
  globalID | Initial Global ID for this TileSet. Use -1 to auto-assign the first available ID.

Returns
  Greater than 0 on success (the Global TileSet id), or a negative error code on failure.

## ◆ createTileSet() [2/2]

Sint32 CRM64Pro::Scene::createTileSet | ( | const string & | sCDCFile,
|  | const string & | sResourceName,
|  | Sint32 | globalID = -1 )

Create a TileSet from a CDC archive resource.

Parameters

  sCDCFile | Path to the CDC archive.
  sResourceName | Name of the resource inside the CDC.
  globalID | Initial Global ID for this TileSet. Use -1 to auto-assign the first available ID.

Returns
  Greater than 0 on success (the Global TileSet id), or a negative error code on failure.

## ◆ createTileSetFromFile()

Sint32 CRM64Pro::Scene::createTileSetFromFile | ( | const string & | sPath,
|  | Sint32 | globalID = -1,
|  | Sint32 | iTileWidth = -1,
|  | Sint32 | iTileHeight = -1 )

Create a TileSet from a file on disk.

Parameters

  sPath | Path to the image file.
  globalID | Initial Global ID for this TileSet. Use -1 to auto-assign the first available ID.
  iTileWidth | Optional tile width override.
  iTileHeight | Optional tile height override.

Returns
  Greater than 0 on success (the Global TileSet id), or a negative error code on failure.

## ◆ setTileAnimation()

Sint32 CRM64Pro::Scene::setTileAnimation | ( | Uint32 | iTileGID,
|  | const vector< Uint32 > & | vFrameGID,
|  | const vector< Sint32 > & | vDuration )

Set a TileSet animation for a tile.

Parameters

  iTileGID | Global tile ID that owns the animation.
  vFrameGID | List of global tile IDs used as animation frames.
  vDuration | List of frame durations in milliseconds.

Returns
  0 on success, or a negative error code on failure.

Note
  All frame tiles must belong to the same TileSet as iTileGID.

## ◆ clearTileAnimation()

Sint32 CRM64Pro::Scene::clearTileAnimation | ( | Uint32 | iTileGID | ) |

Clear a TileSet animation from a tile.

Parameters

  iTileGID | Global tile ID that owns the animation.

Returns
  0 on success, or a negative error code on failure.

## ◆ closeTileSet()

bool CRM64Pro::Scene::closeTileSet | ( | Sint32 | iTN | ) |

Close and destroy a given TileSet.

The affected layers (the ones that use any tile of this TileSet) will be disabled.

Parameters

  iTN | Global ID or any tile of the TileSet to be removed.

Returns
  true on success, or false on failure.

## ◆ getTileResourceID()

Sint32 CRM64Pro::Scene::getTileResourceID | ( | Sint32 | iTN | ) |

Resolve a Global Tile ID to its internal CRM64Pro Tile Resource ID.

Retrieves the internal resource handle (ID) for the tile associated with the given Global ID. This ID can be used with tileMgr() to modify tile attributes (animations, collision, etc.) directly.

Parameters

  iTN | Global Tile ID (from the map data).

Returns
  Greater than 0 on success (the Tile resource id), or a negative error code on failure.

## ◆ getTileSetType()

eSceneTileSetType CRM64Pro::Scene::getTileSetType | ( | Sint32 | iTN | ) |

Get the TileSet type.

Parameters

  iTN | Global ID or any tile of the TileSet.

Returns
  TileSet type enum value.

## ◆ getTileSetSource()

bool CRM64Pro::Scene::getTileSetSource | ( | Sint32 | iTN,
|  | eSceneStorageMode & | eMode,
|  | string & | sPath,
|  | string & | sFilename )

Get the storage metadata for a TileSet.

Parameters

  iTN | Global ID of the TileSet.
  eMode | Output storage mode (Disk, CDC, or Internal).
  sPath | Output path or CDC archive name.
  sFilename | Output TSX or image filename.

Returns
  true on success, or false on failure.

## ◆ setTileSetSource()

bool CRM64Pro::Scene::setTileSetSource | ( | Sint32 | iTN,
|  | eSceneStorageMode | eMode,
|  | const string & | sPath,
|  | const string & | sFilename )

Set the storage metadata for a TileSet.

Used to specify how the TileSet should be referenced when saving the level.

Parameters

  iTN | Global ID of the TileSet.
  eMode | Storage mode (Disk, CDC, or Internal).
  sPath | Path or CDC archive name.
  sFilename | TSX or image filename.

Returns
  true on success, or false on failure.