Jump to content
  • Advertisement
Sign in to follow this  
Alian Vesuf

SDL Color Key Problems

This topic is 2082 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. Im having strange problem with ColorKey in SDL. When i use small images the colorkey does not complete and it leaves some stroke around the sprite. I dont know why. Strangely with bigger images it works fine. 


Also i have map file with different values that are mapped to different tiles in the bmp file. The bmp file has that blueish background. The program reads the map file and the bmp file and based on values in the map file it Blits different tiles on screen. The ground appears good but when it comes to those wooden rails it leaves some stroke.




Here is some code :

Sprite class:

class Sprite
          SDL_Surface *image;
        void LoadImage(const char *src);
        void AddTransparency(Uint32 ColorKey);

Somewhere in the main code:

SDL_Surface *Screen; //main screen surface
Sprite Background;
Sprite Tiles;
Uint32 ColorKey = SDL_MapRGB(Screen->format, 0x5E, 0x81, 0xA2);

And in the AddTransparency function i do :

void Sprite::AddTransparency(Uint32 ColorKey){
       SDL_SetColorKey(image, SDL_SRCCOLORKEY, ColorKey);
Edited by aliasc

Share this post

Link to post
Share on other sites

Actually i solved the problem by using more light strong colors like light green, light orange cyan or magenta. These are strong colors with maximum white which gives more light to it and it seems that they are easier for SDL to apply clear color keying. Thanks for no replies hope this wil help someone.

Share this post

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