I have a BMP file which is supposed to be a player sprite.
The thing is that, since BMP doesn't support transparency, I have to go another way to achieve it.
I've read a tutorial on SetColorKey and SetAlpha, but I just don't get it - how do I define the color which should be left out? :?
I'd appreciate an explanation, or better yet - a piece of code with that in it.
paul_nicholls
28-01-2009, 03:44 AM
I have a BMP file which is supposed to be a player sprite.
The thing is that, since BMP doesn't support transparency, I have to go another way to achieve it.
I've read a tutorial on SetColorKey and SetAlpha, but I just don't get it - how do I define the color which should be left out? :?
I'd appreciate an explanation, or better yet - a piece of code with that in it.
Here is some code that may help - I use it in my SDL sprite unit:
Procedure TSDLSprite.SetAlpha(Const AValue : Byte);
Begin
If Not Assigned(FSurface) Then Exit;
Falpha := AValue;
If Falpha <> 255 Then
SDL_SetAlpha(FSurface,SDL_SRCALPHA,Falpha)
Else
SDL_SetAlpha(FSurface,0,255);
End;
{................................................. .............................}
{................................................. .............................}
Procedure TSDLSprite.SetTransparent(Const AValue : Boolean);
Begin
If Not Assigned(FSurface) Then Exit;
FTransparent := AValue;
If FTransparent Then
SDL_SetColorKey(FSurface,SDL_SRCCOLORKEY,SDL_MapRG B(FSurface^.format,Fr,Fg,Fb))
Else
SDL_SetColorKey(FSurface,0,0);
End;
{................................................. .............................}
{................................................. .............................}
Procedure TSDLSprite.SetTransparentColour(Const r,g,b : Byte);
Begin
Fr := r;
Fg := g;
Fb := b;
End;
{................................................. .............................}
{................................................. .............................}
FSurface is an internal PSDL_Surface stored in each sprite containing the picture data.
Fr, Fg, Fb are the R, G, and B (0..255) byte values respectively of the transparent colour to be used for the colour-keying (transparency)
Falpha is the byte value of how much the sprite is opaque (0 - not there, 255 is totally opaque)
I hope this helps :-)
cheers,
Paul
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.