CRM32Pro SDK  v5.22
List of all members | Public Member Functions
CRM32Pro_CTile Class Reference

CTile. More...

Detailed Description

CTile.

Tile engine class.

Public Member Functions

void Clean ()
 Clean and reset the content of current tile. More...
 
unsigned char Create (char *filebmp, char *nametile)
 Create a tile from an external image file(BMP/PNG) More...
 
unsigned char Create (SDL_Surface *surf, char *nametile)
 Create a tile from a surface. More...
 
int Draw (SDL_Surface *dumpto=NULL, int iTID=0)
 Draw a tile in a destination surface. More...
 
int GetAlpha ()
 Get alpha blending information. More...
 
int GetColorKey ()
 Get the current color key. More...
 
char * GetName ()
 Get the tile name. More...
 
int GetOffset (int *, int *)
 Get X(width) and/or Y(height) for each tile on the tileset. More...
 
int GetPosX ()
 Get position X. More...
 
int GetPosY ()
 Get position Y. More...
 
int GetSizeX (void)
 Get total X(width) size of the tile(or tileset) surface. More...
 
int GetSizeY (void)
 Get total Y(height) size of the tile(or tileset) surface. More...
 
SDL_Surface * GetSurface ()
 Get the surface of tile. More...
 
void Info ()
 Print a lot of useful tile information. Very useful for debugging purposes.
 
unsigned char Load (char *fileDPF, char *name, char *typeblock="TILE2")
 Load a tile from a DPF(using a filename) More...
 
unsigned char Load (int idDPF, char *name, char *typeblock="TILE2")
 Load a tile from a DPF(using an idDPF) More...
 
int Save (char *fileDPF, char *typeblock="TILE2")
 Save this tile to a DPF(using a filename) More...
 
int Save (int idDPF, char *typeblock="TILE2")
 Save this tile to a DPF(using an idDPF) More...
 
void SetAlpha (int shade)
 Set the alpha per-surface. More...
 
void SetColorKey (int r, int g, int b)
 Set a colorkey using RGB values. More...
 
void SetColorKey (int CKey)
 Set a colorkey using a packed integer. More...
 
void SetName (char *name)
 Set a new name for the tile. More...
 
void SetPosition (int x, int y)
 Set a new tile position. More...
 
unsigned char SetTileSet (int isTS, int iWidthOffset, int iHeightOffset)
 Convert a single tile on a full tileset and the reverse operation. More...
 

Member Function Documentation

void CRM32Pro_CTile::Clean ( )

Clean and reset the content of current tile.

Useful to reuse the tile object with another content without use 'delete' and 'new' operators.

unsigned char CRM32Pro_CTile::Create ( char *  filename,
char *  nametile 
)

Create a tile from an external image file(BMP/PNG)

By default, alpha per surface and colorkey are disabled. If you want to use it, you must set it after the tile creation.
But if your PNG already has alpha per-pixel information, it will be automatically used.

Parameters
filenameImage file name, with its full path, containing the tile
nametileDesired tile name
Returns
0 Failed
1 Ok
unsigned char CRM32Pro_CTile::Create ( SDL_Surface *  surf,
char *  nametile 
)

Create a tile from a surface.

It supports alpha per pixel surfaces or alpha per surface with/without colorkey.

Parameters
surfSDL surface to create tile
nametilename for the tile
Returns
0 Failed
1 Ok
int CRM32Pro_CTile::Draw ( SDL_Surface *  dumpto = NULL,
int  iTID = 0 
)

Draw a tile in a destination surface.

Parameters
dumptodestination surface, by default is CRM32Pro.screen.
iTIDtile id from the current tileset. From 1 to number of tiles.
You can OR'ed it with any (but only one) TILEFFECT_xxx flag for drawing the tile using special effects. Bits 32,31 and 30 are reserved for these effects.
Returns
0 Failed
1 Ok
int CRM32Pro_CTile::GetAlpha ( )

Get alpha blending information.

To extend the information about the alpha blending, you can read How SDL Alpha works (based on SDL documentation).

Returns
-1 Failed
From 0(transparent) to 254(almost full opaque) and alpha per-surface enabled
255 Alpha per-surface disabled
256 Alpha per-pixel enabled
int CRM32Pro_CTile::GetColorKey ( )

Get the current color key.

To unpack the returned value to independent RGB values, you can use SDL_GetRGB().

Returns
-1 Colorkey disabled
Any other positive or 0 value, the packed colorkey on an integer.
char * CRM32Pro_CTile::GetName ( )

Get the tile name.

Returns
a pointer to tile name
int CRM32Pro_CTile::GetOffset ( int *  x,
int *  y 
)

Get X(width) and/or Y(height) for each tile on the tileset.

Parameters
xpointer to an integer to store the width for each frame. NULL if you do not want to query it.
ypointer to an integer to store the height for each frame. NULL if you do not want to query it.
Returns
0 Failed and it is not a tileset.
1 Ok and it is a tileset.
int CRM32Pro_CTile::GetPosX ( )

Get position X.

Returns
x position of tile
int CRM32Pro_CTile::GetPosY ( )

Get position Y.

Returns
y position of tile
int CRM32Pro_CTile::GetSizeX ( void  )

Get total X(width) size of the tile(or tileset) surface.

Returns
size x of tile surface
int CRM32Pro_CTile::GetSizeY ( void  )

Get total Y(height) size of the tile(or tileset) surface.

Returns
size y of tile surface
SDL_Surface * CRM32Pro_CTile::GetSurface ( )

Get the surface of tile.

Returns
NULL Failed
any other value, a pointer to the SDL surface
unsigned char CRM32Pro_CTile::Load ( char *  fileDPF,
char *  name,
char *  typeblock = "TILE2" 
)

Load a tile from a DPF(using a filename)

Parameters
fileDPFname and optional path of a DPF that contains the tile
namename of tile
typeblockby default is "TILE2", don't change it unless you know what you are doing
Returns
0 Failed
1 Ok
unsigned char CRM32Pro_CTile::Load ( int  idDPF,
char *  name,
char *  typeblock = "TILE2" 
)

Load a tile from a DPF(using an idDPF)

Parameters
idDPFID of the opened DPF
namename of tile
typeblockby default is "TILE2", don't change it unless you know what you are doing
Returns
0 Failed
1 Ok
int CRM32Pro_CTile::Save ( char *  fileDPF,
char *  typeblock = "TILE2" 
)

Save this tile to a DPF(using a filename)

Parameters
fileDPFname and optional path of a DPF to store this tile.
typeblockby default is "TILE2", don't change it unless you know what you are doing
Returns
-1 Tile already exists.
0 Failed.
any other positive value, Ok and packed size of the added tile
int CRM32Pro_CTile::Save ( int  idDPF,
char *  typeblock = "TILE2" 
)

Save this tile to a DPF(using an idDPF)

Parameters
idDPFID of the opened DPF.
typeblockby default is "TILE2", don't change it unless you know what you are doing
Returns
-1 Tile already exists.
0 Failed.
any other positive value, Ok and packed size of the added tile
void CRM32Pro_CTile::SetAlpha ( int  shade)

Set the alpha per-surface.

A surface with enabled alpha blending(per-pixel or per-surface) will be never created on video memory if alpha blending is not supported by the hardware. Right now, only glSDL supports it.
With per-pixel alpha, per-surface alpha is useless, so any attempt to activate it will be ignored.

Note that enabling and disabling the alpha blending on the execution time could slowdown your graphic performance.
To extend the information about the alpha blending, you can read How SDL Alpha works (based on SDL documentation).

Parameters
shadeinteger from 0(transparent) to 254(almost full opaque) to enable the per-surface alpha or 255(full opaque) to disable it.
void CRM32Pro_CTile::SetColorKey ( int  r,
int  g,
int  b 
)

Set a colorkey using RGB values.

With alpha per pixel, colorkey is useless.
In OpenGL mode (glSDL), changing the colorkey after loading/creating the tile could slowdown your graphic performance.

Parameters
rred component (0-255). -1 to disable the colorkey.
ggreen component (0-255). -1 to disable the colorkey.
bblue component (0-255). -1 to disable the colorkey.
void CRM32Pro_CTile::SetColorKey ( int  CKey)

Set a colorkey using a packed integer.

To pack the integer with RGB values, you can use SDL_MapRGB().
With alpha per pixel, colorkey is useless.
In OpenGL mode (glSDL), changing the colorkey after loading/creating the tile could slowdown your graphic performance.

Parameters
CKeypacked integer with colorkey. You can also use -1 to disable the colorkey.
void CRM32Pro_CTile::SetName ( char *  name)

Set a new name for the tile.

Parameters
namepointer to the new name. Maximum of 31 characters.
void CRM32Pro_CTile::SetPosition ( int  x,
int  y 
)

Set a new tile position.

Parameters
xdesired new x position
ydesired new y position
unsigned char CRM32Pro_CTile::SetTileSet ( int  isTS,
int  iWidthOffset,
int  iHeightOffset 
)

Convert a single tile on a full tileset and the reverse operation.

Since v5.21, the conversion allows to have non-exact offset division, the remainder parts of the image will not be used.

Parameters
isTS0 to convert a full tileset on a single tile. Any other value to convert a single tile on a full tileset
iWidthOffsetwidth offset to do the conversion. Negative and 0 values are converted to 1.
iHeightOffsetheight offset to do the conversion. Negative and 0 values are converted to 1.
Returns
0 Failed(it is not a tileset)
1 Ok

The documentation for this class was generated from the following files: