Public Group

# Setting multiple colorkeys

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

## Recommended Posts

On the Lazy Foo tutorial, I am setting a color key so that the background of my image is transperant. Right now I am playing around with this new function call and am throwing multiple bitmaps onto one screen. each bitmap has a different background color. I am wondering how I can have a different colorkey depending on the image. right now I am using the SDL_SetColorKey() in a load_image function:
SDL_Surface *load_image( std::string filename )
{

//The optimized surface that will be used
SDL_Surface* optimizedImage = NULL;

{
//Create an optimized surface

//Free the old surface

//If the surface was optimized
if( optimizedImage != NULL )
{
//Color key surface
SDL_SetColorKey( optimizedImage, SDL_RLEACCEL | SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0xFF, 0xFF, 0xFF ) );
}
}

//Return the optimized surface
return optimizedImage;
}


if i try and add another SetColorKey line it just goes for the last one written.

##### Share on other sites
I forgot to mention that the way I got it to work was by making another load_image function that sets a different colorkey and just call a different load_image function depending on the image. Is there a better way to go about this?

• 33
• 15
• 23
• 10
• 19