About SDL_SetColorKey

How to SetColorKey twice in 1 surface

image

i try this but not working

You can only have one color key per surface. Calling SDL_SetColorKey a second time will simply replace the previous one.

1 Like

Thanks for your answer.
I think maybe i can create new surface, copy the old->new and do it
Do you know better way to do it?

Yeah, that sounds like it should work.

Other ways I can think of are:

  • Use an image editor to modify the file so that all pixels that should not be shown have the same colour.
  • Use a palette. This will allow you to have multiple pixel values that are treated as transparent but this also means you’re limited to only 255 colours.
  • Loop over all the pixels and overwrite the ones that you don’t want to show with the color key (or don’t use a color key and instead use a surface with an alpha channel and make the pixels fully transparent).
1 Like