Sign in to follow this  

[SDL] Transparent entityes

Recommended Posts

Hello all.
First of all happy new year to everyone. I hope someone can help me with this:
Basickly I have a draw function, a transparent function and a function for loading entityes. My problem is that whenever I try to apply my transparent function on an entity it just keeps its color, nothing changes. Here are the functions :
//Draw Function
bool GameSurface::OnDraw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y) {
if(Surf_Dest == NULL || Surf_Src == NULL) {
return false;

SDL_Rect DestR;

DestR.x = X;
DestR.y = Y;

SDL_BlitSurface(Surf_Src, NULL, Surf_Dest, &DestR);

//Load Function

SDL_Surface* GameSurface::OnLoad(std::string filename) {
SDL_Surface* Surf_Temp = NULL;
SDL_Surface* Surf_Return = NULL;

if((Surf_Temp = IMG_Load(filename.c_str())) == NULL) {
return NULL;

Surf_Return = SDL_DisplayFormatAlpha(Surf_Temp);

return Surf_Return;

//Transparent function
bool GameSurface::Transparent(SDL_Surface* Surf_Dest, int R, int G, int B)
if(Surf_Dest == NULL) return true;
SDL_SetColorKey(Surf_Dest, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(Surf_Dest->format, R, G, B));
return true;

//Entity load function
bool Entity::OnLoad(std::string filename, int Widght, int Height, int MaxFrames){
if((Surf_Entity = GameSurface::OnLoad(filename.c_str())) == NULL) return false;

GameSurface::Transparent(Surf_Entity, 255, 0, 255);

this->Widght = Widght;
this->Height = Height;
Anim_Control.MaxFrames = MaxFrames;

return true;
Thanks in advance ! PS: I know there isnt much commenting going on but if needed I will provide some

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this