A Quick and Dirty VCL Sprite Engine - Part III

By: John Ray Thomas

Abstract: Allow a transparency color, to show the background around irregular shaped sprites.

Allow a transparency color to show the background around irregular shaped sprites.

Transparancies are a piece of cake with TBitmap. Just two properties need to be set. First, the TBitmap::TransparentColor should set to the TColor value (as an BGR triple, i.e. 0x00FF0000 for blue) that you wish not to be drawn when the image is BLT'd. Then set the TBitmap::Transparent property to true. If the BGR value is not known at design time this value can easily be set by reading the value of the top,left pixel (since most people use this as the color key). Setting up a transparent bitmap at runtime is shown in the following source code. TBitmap will use the bottom-left pixel for it's transparent color if one is not specified.

bmp->TransparencyColor = bmp->Canvas->Pixels[0,0];
bmp->Transparent = true;

The following image is an example of color keyed image. Any color not in the image will do, therefore I suggest something bright like "hot pink".

Server Response from: ETNASC04