Jump to content
  • Advertisement
Sign in to follow this  
?????????????????

[SDL] Transparent entityes

This topic is 2532 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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);
SDL_FreeSurface(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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!