0

In the past, I have always made my own sprite sheets, and just made them transparent. But I always see sprite sheets with a pinkish color as a background. How would you key this out in a game?

also which is better? using a transparent .png file? or having a solid background color?

enter image description here

In case anyone is wondering, I use the BufferedImage class and I getSubImage.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Steven
  • 833
  • 3
  • 11
  • 18
  • 2
    Personally, transparent PNG is easier, but it may require more processing when loading, but then, I don't need to take care of it. – MadProgrammer Aug 23 '13 at 01:45
  • 1
    Your ultimate goal is to make the background of your sprite transparent, or is it to develop a piece of software that does that? – jsedano Aug 23 '13 at 01:46
  • sometimes editors show transparent as an alternate colour/pattern – BevynQ Aug 23 '13 at 01:53
  • 3
    See [this answer](http://stackoverflow.com/a/13913561/418556) for a way to turn a single color transparent in an image. – Andrew Thompson Aug 23 '13 at 02:11

2 Answers2

2

There's typically three ways to make sprites transparent, either using a separate alpha channel, by using separate bit mask, or simply using a transparent color. The latter is usually used with indexed color, as it is as simple as replacing the color of one of the indexes (the one with the pink color in your case) with transparency.

The only advantage I see with this technique is preserving memory. But I haven't made many games, so there might be other reasons for doing this.. ;-)

Harald K
  • 26,314
  • 7
  • 65
  • 111
  • The disadvantage of this method is that it only works for 1-bit transparency. "Real" PNG transparency can be 1-bit -- on or off -- or a full 8-bit range. It adds an entire new color channel, though, so only use it if you *need* variable transparency. – Jongware Sep 02 '13 at 20:19
0

If you dont mind using a library, i use lwjgl,and make spritesheets using texturepacker.

Texturepacker generates xml files for textures automatically, and places the textures all on one png.

Once i do that, i use gimp, and just use the eraser tool until the background is transparent.

Then in your program you just have to type

glEnable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

and the transparency should work automatically, its a bit more of a pain to actually set up accessing the spritesheets and such though

Ben Marshall
  • 171
  • 2
  • 12