• Advertisement
Sign in to follow this  

Setting multiple colorkeys

This topic is 4045 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

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 image that's loaded
    SDL_Surface* loadedImage = NULL;
    
    //The optimized surface that will be used
    SDL_Surface* optimizedImage = NULL;
    
    //Load the image
    loadedImage = IMG_Load( filename.c_str() );
    
    //If the image loaded
    if( loadedImage != NULL )
    {
        //Create an optimized surface
        optimizedImage = SDL_DisplayFormat( loadedImage );
        
        //Free the old surface
        SDL_FreeSurface( loadedImage );
        
        //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 this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement