< index
< 5. Image toolkit
|
=====================================
5.8 Blitting an image on a console
=====================================
|
|
You can draw an image on a console (by changing the cells background color) :
The first function allows you to specify the floating point coordinates of the center
of the image, and its scale and rotation angle.
The image will be rendered with sub-cell accuracy. For example, if you increase x by 0.01 per frame,
you will achieve a smooth scrolling effect.
C++ : void TCODImage::blit(TCODConsole *console, float x, float y, TCOD_bkgnd_flag_t bkgnd_flag = TCOD_BKGND_SET, float scalex=1.0f, float scaley=1.0f, float angle=0.0f) const
C : void TCOD_image_blit(TCOD_image_t image, TCOD_console_t console, int x, int y, TCOD_bkgnd_flag_t bkgnd_flag, float scalex, float scaley, float angle)
Parameter | Description |
image | In the C version, the image handler, obtained with the load function. |
console | The console on which the image will be drawn. In the C version, use NULL for the root console. |
x,y | Coordinates in the console of the center of the image. |
flag | This flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t. |
scale | Scale coefficient. Must be > 0.0. |
angle | Rotation angle in radians. |
Example :
C++ : TCODImage *pix = TCODImage("mypix.bmp");
pix->blit(TCODConsole::root,40.0f,25.0f);
C : TCOD_image_t pix = TCOD_image_new(80,50);
TCOD_image_blit(pix,NULL,40,25,TCOD_BKGND_SET,1.0f,1.0f,0.0f);
The second function allows you to easily map an image to a specific part of a console, by
specifying a rectangular part of the console (upper-left corner and size).
C++ : void TCODImage::blitRect(TCODConsole *console, int x, int y, int w=-1, int h=-1, TCOD_bkgnd_flag_t bkgnd_flag = TCOD_BKGND_SET ) const
C : void TCOD_image_blit_rect(TCOD_image_t image, TCOD_console_t console, int x, int y, int w, int h, TCOD_bkgnd_flag_t bkgnd_flag)
Parameter | Description |
image | In the C version, the image handler, obtained with the load function. |
console | The console on which the image will be drawn. In the C version, use NULL for the root console. |
x,y | Coordinates in the console of the upper-left corner of the image. |
w,h | Dimension of the image on the console. Use -1,-1 to use the image size. |
flag | This flag defines how the cell's background color is modified. See TCOD_bkgnd_flag_t. |
Example :
C++ : TCODImage *pix = TCODImage("mypix.bmp");
// blitting the image without scaling it
pix->blitRect(TCODConsole::root,40,25);
C : TCOD_image_t pix = TCOD_image_new(10,10);
/* down-scaling a 10x10 image to a 5x5 zone */
TCOD_image_blit_rect(pix,NULL,40,25,5,5,TCOD_BKGND_SET);