This toturial was written for me by Imran Khan (email@example.com,
When you run the previous version of the program, all things are fine except the Grey color around the character. This Grey Color is the image background color.if the picture got pink color as background it will show the pink color. We want to elimate this color.So that it will look more better.
First Declare an instance of ColorKey class.
All the things are same except these
ck.ColorSpaceHighValue = 10066329; //RGB(153, 153, 153)
We specify the Range of the color to make transparent, Here we want to make Grey to be transparent so we give the same values in both arguments. (153, 153, 153) is the RGB combination of Grey.One can make more then 1 color Transparent.
To Convert RGB(153,153,153) into 1 integer , we have to follow the following mathematical method:
Red = 1, Green = 256 and Blue = 65536. So to translate an RGB value into integer you multiply each color value by the nueric value that corresponds to it.As we have taken here Gray then
153 * 1 (red) = 153 , 153 * 256(green) = 39168 , 153 * 65536 (blue) = 10027008,
Now add thes values:
153 + 39168 + 10027008 = 10066329
Then we delcare a character surface object ( we done this before )
The last line sets the ColorKey that we created eariler. The first argument specifies that we will use the source which is our surface for transparency and then the second argument is the ColorKey structure we made eariler.
Now replace a single line in ShowSurface( ) method
New Version :
We must specify that we will use a color key in the DrawFastFlags, so we change the flags to SourceColorKey which will cause the color we set in the ColorKey to be drawn transparent.
Now when you run the Program, You will see no Gray color around character.
|Correspondence about this page|
This site may have errors. Don't use for critical systems.