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

TileEngine Object class. More...

Detailed Description

TileEngine Object class.

Public Member Functions

bool info (Sint32 iMode=-1) override
 Request detailed TileEngine object information.
const string & getName () const override
 Get the name.
Uint32 getID () const override
 Get the ID.
Sint32 getWidth ()
 Get the total width of the level in pixels.
Sint32 getHeight ()
 Get the total height of the level in pixels.
bool setLayerCount (Uint32 iNumLayers)
 Set the number of layers.
Sint32 getLayerCount () const
 Get the number of layers.
bool freeLayer (Sint32 layer)
 Free a layer.
bool freeLevel ()
 Free all resources of current level (layer maps and tilesets).
bool setViewport (SDL_Rect *rect)
 Set the desired viewport.
SDL_Rect * getViewport ()
 Get the current viewport.
bool setBackgroundColor (Uint32 iRGBA)
 Set background color.
Uint32 getBackgroundColor () const
 Get background color.
Sint32 getModificationDate (string &sDate)
 Get the level modification date (last save level date).
Sint32 getCreationDate (string &sDate)
 Get the level creation date (first save level date).
Sint32 loadTileSet (Sint32 idRes, Sint32 globalID=-1)
 Load a TileSet from a Resource ID (Tile, Image or XML).
Sint32 loadTileSet (const string &sCDCFile, const string &sResourceName, Sint32 globalID=-1)
 Load a TileSet from a CDC archive.
Sint32 loadTileSetFromFile (const string &sPath, Sint32 globalID=-1, Sint32 iTileWidth=-1, Sint32 iTileHeight=-1)
 Load a TileSet from an external file.
bool unloadTileSet (Sint32 iTN)
 Unload a given TileSet.
Sint32 getTile (Sint32 iTN)
 Get the Tile id.
eTileEngineTileSetType getTileSetType (Sint32 iTN)
 Get the TileSet type.
bool getTileSetSource (Sint32 iTN, eTileSetStorageMode &eMode, string &sPath, string &sFilename)
 Get the storage metadata for a TileSet.
bool setTileSetSource (Sint32 iTN, eTileSetStorageMode eMode, const string &sPath, const string &sFilename)
 Set the storage metadata for a TileSet.
bool setLayerFeatures (Sint32 layer, Uint32 iFeatures, bool bEnable)
 Set the layer features.
Uint32 getLayerFeatures (Sint32 layer)
 Get the layer features.
bool setLayerAlphaMod (Sint32 layer, Sint32 alpha)
 Set layer alpha modulation used for rendering this layer.
Sint32 getLayerAlphaMod (Sint32 layer)
 Get layer alpha modulation.
bool setLayerParallaxRatio (Sint32 layer, float fPRX, float fPRY)
 Set the layer parallax ratio.
Sint32 getLayerParallaxRatio (Sint32 layer, float *fPRX, float *fPRY)
 Get current layer parallax ratio.
Sint32 setLayerPosition (Sint32 layer, float xpos=TE_KEEP_VALUE, float ypos=TE_KEEP_VALUE)
 Set the layer absolute position (in pixels).
Sint32 getLayerPosition (Sint32 layer, float *xpos, float *ypos)
 Get the current layer position (in pixels).
bool setLayerAutoScroll (Sint32 layer, float xspeed=TE_KEEP_VALUE, float yspeed=TE_KEEP_VALUE)
 Set the layer AutoScroll speed (in pixels per second).
Sint32 getLayerAutoScroll (Sint32 layer, float *xspeed, float *yspeed)
 Get the layer AutoScroll speed (in pixels per seconds).
bool setLayerMapData (Sint32 layer, TE_MapData *map)
 Assign a mapdata to the given layer.
TE_MapDatagetLayerMapData (Sint32 layer)
 Get current mapdata on the layer.
bool setLayerOnUpdateEnd (Sint32 layer, TE_OnLayerEnd myfunc)
 Set an event function (onUpdateEnd) to be called when the engine finishes updating the layer.
TE_OnLayerEnd * getLayerOnUpdateEnd (Sint32 layer)
 Get current onUpdateEnd event function if any.
bool setLayerOnRenderEnd (Sint32 layer, TE_OnLayerEnd myfunc)
 Set an event function (onRenderEnd) to be called when the engine finishes rendering the layer.
TE_OnLayerEnd * getLayerOnRenderEnd (Sint32 layer)
 Get current onRenderEnd event function if any.
bool getLayerName (Sint32 layer, string &sName)
 Get the layer name.
bool setLayerName (Sint32 layer, const string &sName)
 Set a new layer name.
bool setLayerGridColor (Sint32 layer, Uint32 iColor)
 Set the grid color for the base mapdata.
bool screen2LayerCell (Sint32 layer, Sint32 sx, Sint32 sy, Sint32 *cx, Sint32 *cy)
 Convert screen coordinates into layer cell (tile) indices.
bool screen2LayerAbsolute (Sint32 layer, Sint32 sx, Sint32 sy, Sint32 *px, Sint32 *py)
 Convert screen coordinates to absolute layer pixel coordinates.
Sint32 moveLayer (Sint32 layer, float x, float y)
 Move the layer by adding or subtracting the given X/Y values.
Sint32 update (Sint32 layer=0)
 Update status of the TileEngine.
Sint32 render (Sint32 layer=0, Sint32 idRes=0)
 Render the visible layers.
Sint32 importLayerFromFile (Sint32 layer, const string &sFile, const string &sLayerName, Sint32 tileSizeX, Sint32 tileSizeY, float maxDevPercentage=100.0, Sint32 iCK=-1)
 Import an image file (BMP or PNG) into a layer.
Sint32 importLayerFromImage (Sint32 layer, Sint32 idImg, const string &sLayerName, Sint32 tileSizeX, Sint32 tileSizeY, float maxDevPercentage=100.0, Sint32 iCK=-1)
 Import an image into a layer.
Sint32 exportLayerToFile (Sint32 layer, const string &sFile)
 Export a layer to an external PNG image.
Sint32 exportLayerToImage (Sint32 layer, Sint32 idImg)
 Export a layer to an image.
Sint32 save (const string &sTMXFile, const string &sLevelName="", const string &sCDCFile="", bool bForce=false)
 Save level to native C64TE format (TMX-based).

Member Function Documentation

◆ info()

bool CRM64Pro::TileEngine::info ( Sint32 iMode = -1)
override

Request detailed TileEngine object information.

Writes information to the default log.

Parameters
iMode-1 for displaying information of all layers or greater than 0 for displaying only information of the give layer id.
Returns
true on success, or false on failure.

◆ getName()

const string & CRM64Pro::TileEngine::getName ( ) const
override

Get the name.

Returns
The object name.

◆ getID()

Uint32 CRM64Pro::TileEngine::getID ( ) const
override

Get the ID.

Returns
Object ID.

◆ getWidth()

Sint32 CRM64Pro::TileEngine::getWidth ( )

Get the total width of the level in pixels.

Calculates the maximum width based on the largest layer (map or image).

Returns
Total width in pixels.

◆ getHeight()

Sint32 CRM64Pro::TileEngine::getHeight ( )

Get the total height of the level in pixels.

Calculates the maximum height based on the largest layer (map or image).

Returns
Total height in pixels.

◆ setLayerCount()

bool CRM64Pro::TileEngine::setLayerCount ( Uint32 iNumLayers)

Set the number of layers.

Parameters
iNumLayersnumber of layers to allocate. If current layers are less than iNumLayers, allocates empty new layers. Otherwise removes layers using freeLayer().
Returns
true on success, or false on failure.

◆ getLayerCount()

Sint32 CRM64Pro::TileEngine::getLayerCount ( ) const

Get the number of layers.

Returns
The number of allocated layers.

◆ freeLayer()

bool CRM64Pro::TileEngine::freeLayer ( Sint32 layer)

Free a layer.

Releases the mapdata and resets all layer settings, leaving the slot empty and ready for reuse.

Parameters
layerSelected layer to free (from 1 to number of allocated layers).
Returns
true on success or false on failure.
Note
To remove the layer slot, use setLayerCount().

◆ freeLevel()

bool CRM64Pro::TileEngine::freeLevel ( )

Free all resources of current level (layer maps and tilesets).

Resets the current level. All layers are reset but layer slots are kept. Preserves viewport, level name and number of allocated layers.

Returns
true on success or false on failure.

◆ setViewport()

bool CRM64Pro::TileEngine::setViewport ( SDL_Rect * rect)

Set the desired viewport.

You can change the viewport at any time even while you are rendering your application. The width and height of the viewport can not be greater than values of the smallest layer (excluding the ones with looping features), otherwise, it will be automatically adjusted.

Parameters
rectPointer to SDL_Rect with the desired viewport. If the rect width or height is 0, it will use the whole target (a valid screen or image handle).
Returns
true on success or false on failure.

◆ getViewport()

SDL_Rect * CRM64Pro::TileEngine::getViewport ( )

Get the current viewport.

Returns
Pointer to a SDL_Rect with the current viewport

◆ setBackgroundColor()

bool CRM64Pro::TileEngine::setBackgroundColor ( Uint32 iRGBA)

Set background color.

Parameters
iRGBAbackground color to set in the format RGBA. When A is 0 (totally transparent), the background color is disabled.
Returns
true on success or false on failure.

◆ getBackgroundColor()

Uint32 CRM64Pro::TileEngine::getBackgroundColor ( ) const

Get background color.

Returns
the background color in format RGBA. When A is 0 (totally transparent, the background color is disabled)

◆ getModificationDate()

Sint32 CRM64Pro::TileEngine::getModificationDate ( string & sDate)

Get the level modification date (last save level date).

Parameters
sDatea string containing the date.
Returns
0 on success, or a negative error code on failure.

◆ getCreationDate()

Sint32 CRM64Pro::TileEngine::getCreationDate ( string & sDate)

Get the level creation date (first save level date).

Parameters
sDatea string containing the date.
Returns
0 on success, or a negative error code on failure.

◆ loadTileSet() [1/2]

Sint32 CRM64Pro::TileEngine::loadTileSet ( Sint32 idRes,
Sint32 globalID = -1 )

Load a TileSet from a Resource ID (Tile, Image or XML).

Parameters
idResID of a Tile or Image resource.
  • Tile: Loads normally.
  • Image: Wraps in a Tile as a TETT_COLLECTION (single tile).
globalIDGlobal ID for this TileSet. Default -1 to find a valid gID.
Returns
greater than 0 on success (the Global ID) or a negative error code on failure.

◆ loadTileSet() [2/2]

Sint32 CRM64Pro::TileEngine::loadTileSet ( const string & sCDCFile,
const string & sResourceName,
Sint32 globalID = -1 )

Load a TileSet from a CDC archive.

Parameters
sCDCFilestring with CDC filename.
sResourceNamestring with the resource name inside the CDC.
  • Ends in .tsx: Loads as TSX.
  • No extension: Tries loading a native Tile resource first, then an Image (as TETT_COLLECTION).
globalIDGlobal ID for this TileSet. Default -1 to find a valid gID. Value 0 not allowed (minimum is 1).
Returns
greater than or equal to 0 on success (the tileset index) or a negative error code on failure.

◆ loadTileSetFromFile()

Sint32 CRM64Pro::TileEngine::loadTileSetFromFile ( const string & sPath,
Sint32 globalID = -1,
Sint32 iTileWidth = -1,
Sint32 iTileHeight = -1 )

Load a TileSet from an external file.

Parameters
sPathstring with the file path (e.g., "maps/tileset.tsx" or "gfx/sheet.png").
  • Ends in .tsx: Loads as TSX.
  • Ends in .png/.bmp: Loads as Image (uses iTileWidth/Height).
globalIDGlobal ID for this TileSet. Default -1.
iTileWidthTile width (only for Image loading). -1 for TETT_COLLECTION (single tile).
iTileHeightTile height (only for Image loading). -1 for TETT_COLLECTION (single tile).
Returns
greater than or equal to 0 on success (the Global ID) or a negative error code on failure.

◆ unloadTileSet()

bool CRM64Pro::TileEngine::unloadTileSet ( Sint32 iTN)

Unload a given TileSet.

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

Parameters
iTNGlobal ID or any tile of the TileSet to be removed.
Returns
true on success or false on failure.

◆ getTile()

Sint32 CRM64Pro::TileEngine::getTile ( Sint32 iTN)

Get the Tile id.

It can be used for modifying any Tile attributes.

Parameters
iTNGlobal ID or any tile of the Tile.
Returns
greater than 0 on success(the CRM64Pro::Tile id) or a negative error code on failure.

◆ getTileSetType()

eTileEngineTileSetType CRM64Pro::TileEngine::getTileSetType ( Sint32 iTN)

Get the TileSet type.

Parameters
iTNGlobal ID or any tile of the TileSet.
Returns
check eTileEngineTileSetType for further information.

◆ getTileSetSource()

bool CRM64Pro::TileEngine::getTileSetSource ( Sint32 iTN,
eTileSetStorageMode & eMode,
string & sPath,
string & sFilename )

Get the storage metadata for a TileSet.

Parameters
iTNGlobal ID of the TileSet.
eModeOutput storage mode (Disk, CDC, or Internal).
sPathOutput path or CDC archive name.
sFilenameOutput TSX or image filename.
Returns
true on success or false on failure.

◆ setTileSetSource()

bool CRM64Pro::TileEngine::setTileSetSource ( Sint32 iTN,
eTileSetStorageMode 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
iTNGlobal ID of the TileSet.
eModeStorage mode (Disk, CDC, or Internal).
sPathPath or CDC archive name.
sFilenameTSX or image filename.
Returns
true on success or false on failure.

◆ setLayerFeatures()

bool CRM64Pro::TileEngine::setLayerFeatures ( Sint32 layer,
Uint32 iFeatures,
bool bEnable )

Set the layer features.

Parameters
layerNumber of layer(from 1 to number of allocated layers)
iFeaturesSee TE_LAYERFEATURE_xxx defines for further information. They can be OR'ed
bEnabletrue for enabling the given iFeatures or false for disabling it.
Returns
true on success or false on failure.
Note
TE_LAYERFEATURE_SHOWGRID only works with layers with mapdata, layers with an image are not working.

◆ getLayerFeatures()

Uint32 CRM64Pro::TileEngine::getLayerFeatures ( Sint32 layer)

Get the layer features.

Parameters
layerNumber of layer(from 1 to number of allocated layers)
Returns
the status iFeatures (see TE_LAYERFEATURE_xxx defines for further information) or 0 on failure.

◆ setLayerAlphaMod()

bool CRM64Pro::TileEngine::setLayerAlphaMod ( Sint32 layer,
Sint32 alpha )

Set layer alpha modulation used for rendering this layer.

Parameters
layerSelected layer to set the alpha value (from 1 to number of allocated layers).
alphaIt ranges from 255 (opaque) to 0 (fully transparent).
Returns
true on success or false on failure.

◆ getLayerAlphaMod()

Sint32 CRM64Pro::TileEngine::getLayerAlphaMod ( Sint32 layer)

Get layer alpha modulation.

Parameters
layerSelected layer to get the alpha value (from 1 to number of allocated layers)
Returns
It ranges from 255 (opaque) to 0 (fully transparent) or a negative error code on failure.

◆ setLayerParallaxRatio()

bool CRM64Pro::TileEngine::setLayerParallaxRatio ( Sint32 layer,
float fPRX,
float fPRY )

Set the layer parallax ratio.

Changes the real speed of any layer without affecting the rest.

Parameters
layerSelected layer to set the parallax ratio (from 1 to number of allocated layers).
fPRXParallax ratio on X axis. 0 makes layer independent on X axis, any other value links it.
fPRYParallax ratio on Y axis. 0 makes layer independent on Y axis, any other value links it. If any linked layer moves, it affects others using this ratio as base.
Returns
true on success or false on failure.

◆ getLayerParallaxRatio()

Sint32 CRM64Pro::TileEngine::getLayerParallaxRatio ( Sint32 layer,
float * fPRX,
float * fPRY )

Get current layer parallax ratio.

Parameters
layerSelected layer to get the parallax ratio (from 1 to number of allocated layers).
fPRXa float pointer filled in with parallax ratio on X axis. If nullptr is passed, the method ignores the retrieving of this value.
fPRYa float pointer filled in with parallax ratio on Y axis. If nullptr is passed, the method ignores the retrieving of this value.
Returns
0 on success, or a negative error code on failure.

◆ setLayerPosition()

Sint32 CRM64Pro::TileEngine::setLayerPosition ( Sint32 layer,
float xpos = TE_KEEP_VALUE,
float ypos = TE_KEEP_VALUE )

Set the layer absolute position (in pixels).

Changes position for linked layers according to parallax ratios. Layers with parallax ratio 0.0 are independent. Requires valid base mapdata or image set. Special flags: TE_KEEP_VALUE (keep axis value), TE_LAYERPOSITION_BEGINNING/MIDDLE/END (move layer, skips smoothing), TE_LAYERPOSITION_CENTER (center based on viewport).

Parameters
layerSelected layer to set position (from 1 to number of allocated layers).
xposFlag or value for X axis position.
yposFlag or value for Y axis position.
Returns
0 on success (no change), 1 on success (changed) or a negative error code on failure.

◆ getLayerPosition()

Sint32 CRM64Pro::TileEngine::getLayerPosition ( Sint32 layer,
float * xpos,
float * ypos )

Get the current layer position (in pixels).

Parameters
layerSelected layer to get its current position (from 1 to number of allocated layers).
xposPointer to float var to store the position on X axis. nullptr if you dont want to retrieve it.
yposPointer to float var to store the position on Y axis. nullptr if you dont want to retrieve it.
Returns
0 on success, or a negative error code on failure.

◆ setLayerAutoScroll()

bool CRM64Pro::TileEngine::setLayerAutoScroll ( Sint32 layer,
float xspeed = TE_KEEP_VALUE,
float yspeed = TE_KEEP_VALUE )

Set the layer AutoScroll speed (in pixels per second).

Changes AutoScroll speed for linked layers according to parallax ratios.

Parameters
layerSelected layer to set autoscroll speed (from 1 to number of allocated layers).
xspeedTE_KEEP_VALUE keeps current X speed. Any other value sets it.
yspeedTE_KEEP_VALUE keeps current Y speed. Any other value sets it.
Returns
true on success or false on failure.

Changing speed of others layers. With ratio=0, independent layer.

◆ getLayerAutoScroll()

Sint32 CRM64Pro::TileEngine::getLayerAutoScroll ( Sint32 layer,
float * xspeed,
float * yspeed )

Get the layer AutoScroll speed (in pixels per seconds).

Parameters
layerSelected layer to get its current AutoScroll speed (from 1 to number of allocated layers).
xspeedPointer to float var to store the speed on X axis. nullptr if you dont want to retrieve it.
yspeedPointer to float var to store the speed on Y axis. nullptr if you dont want to retrieve it.
Returns
0 on success, or a negative error code on failure.

◆ setLayerMapData()

bool CRM64Pro::TileEngine::setLayerMapData ( Sint32 layer,
TE_MapData * map )

Assign a mapdata to the given layer.

If the mapdata is already set, it will remove it following resource control policies (see ::eTileEngineResCtrl for further information)

Parameters
layerSelected layer to try to set a new mapdata (from 1 to number of allocated layers)
mapPointer to a valid mapdata: TE_MapData or a derivated one. nullptr to try to remove the existing mapdata.
Returns
true on success or false on failure.
Note
This method does not work with image layers.

◆ getLayerMapData()

TE_MapData * CRM64Pro::TileEngine::getLayerMapData ( Sint32 layer)

Get current mapdata on the layer.

Parameters
layerSelected layer to try to get its mapdata (from 1 to number of allocated layers).
Returns
a pointer to the TE_MapData/derivated one or nullptr if there is not any assigned.

◆ setLayerOnUpdateEnd()

bool CRM64Pro::TileEngine::setLayerOnUpdateEnd ( Sint32 layer,
TE_OnLayerEnd myfunc )

Set an event function (onUpdateEnd) to be called when the engine finishes updating the layer.

Use nullptr to remove a previous onUpdateEnd event function.

Parameters
layerNumber of layer to set the event function (from 1 to number of allocated layers).
myfuncpointer to your custom event function.
Returns
true on success or false on failure.

◆ getLayerOnUpdateEnd()

TileEngine::TE_OnLayerEnd * CRM64Pro::TileEngine::getLayerOnUpdateEnd ( Sint32 layer)

Get current onUpdateEnd event function if any.

Parameters
layerSelected layer to get current onUpdateEnd event function (from 1 to number of allocated layers).
Returns
a pointer to current event function or nullptr if there is not any assigned.

◆ setLayerOnRenderEnd()

bool CRM64Pro::TileEngine::setLayerOnRenderEnd ( Sint32 layer,
TE_OnLayerEnd myfunc )

Set an event function (onRenderEnd) to be called when the engine finishes rendering the layer.

Use nullptr to remove a previous onRenderEnd event function.

Parameters
layerNumber of layer to set the event function (from 1 to number of allocated layers).
myfuncpointer to your custom event function.
Returns
true on success or false on failure.

◆ getLayerOnRenderEnd()

TileEngine::TE_OnLayerEnd * CRM64Pro::TileEngine::getLayerOnRenderEnd ( Sint32 layer)

Get current onRenderEnd event function if any.

Parameters
layerSelected layer to get current onRenderEnd event function (from 1 to number of allocated layers).
Returns
a pointer to current event function or nullptr if there is not any assigned.

◆ getLayerName()

bool CRM64Pro::TileEngine::getLayerName ( Sint32 layer,
string & sName )

Get the layer name.

Parameters
layerSelected layer to get its name (from 1 to number of allocated layers).
sNamea string containing the layer name.
Returns
true on success or false on failure.

◆ setLayerName()

bool CRM64Pro::TileEngine::setLayerName ( Sint32 layer,
const string & sName )

Set a new layer name.

Parameters
layerSelected layer to set its name (from 1 to number of allocated layers).
sNameThe name to give to the layer e.g. 'layer0'.
Returns
true on success or false on failure.

◆ setLayerGridColor()

bool CRM64Pro::TileEngine::setLayerGridColor ( Sint32 layer,
Uint32 iColor )

Set the grid color for the base mapdata.

It is used for debugging purposes

Parameters
layerSelected layer to set the grid color (from 1 to number of allocated layers).
iColorpacked unsigned int with the color value (RGBA).
Returns
true on success or false on failure.

◆ screen2LayerCell()

bool CRM64Pro::TileEngine::screen2LayerCell ( Sint32 layer,
Sint32 sx,
Sint32 sy,
Sint32 * cx,
Sint32 * cy )

Convert screen coordinates into layer cell (tile) indices.

Useful for identifying which specific tile a player is hovering over.

Parameters
layerSelected layer (from 1 to number of allocated layers).
sxScreen X coordinate (e.g., mouse position).
syScreen Y coordinate (e.g., mouse position).
cxPointer to integer where the Cell X index will be returned.
cyPointer to integer where the Cell Y index will be returned.
Returns
true on success or false on failure.
Note
This method only works with tile layers; it will fail if called on an image layer.

◆ screen2LayerAbsolute()

bool CRM64Pro::TileEngine::screen2LayerAbsolute ( Sint32 layer,
Sint32 sx,
Sint32 sy,
Sint32 * px,
Sint32 * py )

Convert screen coordinates to absolute layer pixel coordinates.

Useful for mouse picking or identifying world positions.

Parameters
layerSelected layer (from 1 to number of allocated layers).
sxScreen X coordinate (e.g., mouse position).
syScreen Y coordinate (e.g., mouse position).
pxPointer to integer where the absolute X position will be returned.
pyPointer to integer where the absolute Y position will be returned.
Returns
true on success, or false if the screen position is outside the viewport.

◆ moveLayer()

Sint32 CRM64Pro::TileEngine::moveLayer ( Sint32 layer,
float x,
float y )

Move the layer by adding or subtracting the given X/Y values.

Changes position for linked layers according to parallax ratios. Layers with parallax ratio 0.0 are independent.

Parameters
layerSelected layer to move (from 1 to number of allocated layers).
xFloat X value, positive or negative. 0 does nothing.
yFloat Y value, positive or negative. 0 does nothing.
Returns
0 on success (no change), 1 on success (changed) or a negative error code on failure.

◆ update()

Sint32 CRM64Pro::TileEngine::update ( Sint32 layer = 0)

Update status of the TileEngine.

Only layers with TE_LAYERFEATURE_UPDATE flag are processed. Calculates autoscroll and pre-calculations for rendering. Call as part of logic code. Optionally update individual layers. Calls onUpdateEnd event function at end of each layer update if it exists.

Parameters
layerDefault 0 updates all layers from 1 (background) to foreground. Any other value updates only that layer.
Returns
0 on success, or a negative error code on failure.

◆ render()

Sint32 CRM64Pro::TileEngine::render ( Sint32 layer = 0,
Sint32 idRes = 0 )

Render the visible layers.

Only layers with TE_LAYERFEATURE_RENDER flag are processed. Uses positions from update() to render cells. Call as part of graphic update code. Select rendering order by calling with specific layers. Calls onRenderEnd at end of each layer. With TE_LAYERFEATURE_SMOOTHSCROLL, interpolates values for smooth scrolling.

Parameters
layerDefault 0 processes all layers. Values 1 (background) to foreground process only that layer.
idResa valid screen. Default tries the default screen. Does not support rendering to an image.
Returns
0 on success, or a negative error code on failure.

◆ importLayerFromFile()

Sint32 CRM64Pro::TileEngine::importLayerFromFile ( Sint32 layer,
const string & sFile,
const string & sLayerName,
Sint32 tileSizeX,
Sint32 tileSizeY,
float maxDevPercentage = 100.0,
Sint32 iCK = -1 )

Import an image file (BMP or PNG) into a layer.

Creates a new base mapdata and tileset. Selected layer must be empty (no mapdata). Level name is used for layer and tileset names.

Parameters
layerSelected layer ID (from 1 to number of allocated layers).
sFilestring containing [directory]+filename+[BMP or PNG extension]. Directory separators '\' and '/' are supported.
sLayerNamelayer name. If empty, file name is used.
tileSizeXTile width to divide image. 0 creates an imagelayer.
tileSizeYTile height to divide image. 0 creates an imagelayer.
maxDevPercentagePercentage of differing pixels before tile is unique. Default 100% gets only identical tiles.
iCKFor images without alpha, this RGB color is transparent. Default -1 (disabled).
Returns
0 on success, or a negative error code on failure.
Note
Tileset has proportional size to tile sizes. Sizes > 4096 trigger a warning (some backends don't support them).

◆ importLayerFromImage()

Sint32 CRM64Pro::TileEngine::importLayerFromImage ( Sint32 layer,
Sint32 idImg,
const string & sLayerName,
Sint32 tileSizeX,
Sint32 tileSizeY,
float maxDevPercentage = 100.0,
Sint32 iCK = -1 )

Import an image into a layer.

Creates a new base mapdata and tileset. Selected layer must be empty (no mapdata). Level name is used for layer and tileset names.

Parameters
layerSelected layer ID (from 1 to number of allocated layers).
idImgImage ID to import.
sLayerNamelayer name. If empty, image name is used.
tileSizeXTile width to divide image. 0 creates an imagelayer.
tileSizeYTile height to divide image. 0 creates an imagelayer.
maxDevPercentagePercentage of differing pixels before tile is unique. Default 100% gets only identical tiles.
iCKFor images without alpha, this RGB color is transparent. Default -1 (disabled).
Returns
0 on success, or a negative error code on failure.
Note
Tileset has proportional size to tile sizes. Sizes > 4096 trigger a warning (some backends don't support them).

◆ exportLayerToFile()

Sint32 CRM64Pro::TileEngine::exportLayerToFile ( Sint32 layer,
const string & sFile )

Export a layer to an external PNG image.

Parameters
layerLayer to export, from 1 to number of allocated layers or 0 to export all layers. The layer must has TE_LAYERFEATURE_RENDER flag.
sFilestring containing the [directory]+filename+[extension].
Returns
0 on success, or a negative error code on failure.

◆ exportLayerToImage()

Sint32 CRM64Pro::TileEngine::exportLayerToImage ( Sint32 layer,
Sint32 idImg )

Export a layer to an image.

Parameters
layerLayer to export, from 1 to number of allocated layers or 0 to export all layers. The layer must has TE_LAYERFEATURE_RENDER flag.
idImgImage ID. The image should not have assigned any surface.
Returns
0 on success, or a negative error code on failure.

◆ save()

Sint32 CRM64Pro::TileEngine::save ( const string & sTMXFile,
const string & sLevelName = "",
const string & sCDCFile = "",
bool bForce = false )

Save level to native C64TE format (TMX-based).

Saves the TileEngine level to the native C64TE format, which is based on Tiled TMX v1.10 (orthogonal, right-down render order). The level can be saved as standalone TMX files on disk or packaged within a CDC archive, with flexible control over TileSet resource locations.

TileSet source handling:

  • If bForce=false (default): Resources respect their original storage mode:
    • TSSM_DISK: References existing disk file (path/filename preserved)
    • TSSM_CDC: References existing CDC archive using "cdc://archive/resource" format
    • TSSM_INTERNAL: Always exported to current destination (created from in-memory objects)
  • If bForce=true: All resources consolidated to target destination:
    • Saving to disk: All resources exported to same directory as TMX
    • Saving to CDC: All resources packaged into same CDC archive

Output modes:

  1. Disk mode (sCDCFile=""): Creates .tmx file and separate .tsx/.png files in sTMXFile directory
  2. CDC mode (sCDCFile specified): Packages resources into CDC archive (behavior depends on bForce)
Parameters
sTMXFilestring containing [directory]+filename+[extension] for the TMX file. Directory separators '\' and '/' are supported. Extension optional.
sLevelNameOptional level name override. If empty, uses current level name.
sCDCFileOptional CDC archive path. If empty, saves as external disk files. If specified, saves to CDC archive (behavior depends on bForce flag).
bForceIf true, consolidates all resources to target destination (disk or CDC). If false (default), respects original resource storage modes.
Returns
0 on success, or a negative error code on failure.
See also
load()