SDL (and other toolkits) can use color keying to make a certain color in an image transparent. Alternatively, you could load a PNG image that supports transparency.
When should I use which?
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communitySDL (and other toolkits) can use color keying to make a certain color in an image transparent. Alternatively, you could load a PNG image that supports transparency.
When should I use which?
JPG is lossy. Don't use that for sprites -- you will end up with nasty artifacts that will look bad. There's a couple reasons you might want to use colur-keying, but they're a bit lost in todays hardware. Taking a quick look at color key advantages:
Pros
Cons
A note about CPU complexity
When you use a color key mapped image, you are still converting this to an image with alpha channels when it reaches the video RAM in all cases. You will need an additional channel to record these pixels as an alpha of 0. Due to this, a pass must be made on the image at load time to account for this. Unfortunately, the consequence for this is a higher overhead during loading. The time may be of no consequence for few images, but it is worth taking note.
In the end, PNG transparency is used mostly in todays standards game as it easy to use and widely decodable for the most part (such as with SDL). Most popular game engines no longer support color keying, this method was mostly used in older engines and systems.
Off the top of my head, libGDX and XNA both do not support color keying. However, the latter does support it on its content pipeline. Which leads into another interesting option...
You can process it at build time
If you really wanted to use color keying to save disk space because you were working on a tight budget disk space wise, you can always choose to store the assets in a color key format and then have them changed and built at build time to the format that is most appropriate.
Concluding
However, in the end do not use JPG for something like a sprite. If you want to use JPGs, use them on something that lossy behavior is acceptable, like 3D textures or photographs of real objects where picture blur is more or less unnoticed.