How can I make the background of my sprite always draw transparent?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
How can I make the background of my sprite always draw transparent?
Use the alpha channel for your images. An alpha of 1 means it's fully opaque, an alpha of 0 means it's fully transparent, and you can also use any alpha value in-between 0 and 1 (note: depending on the format this might be a byte 0-255 rather than a float 0-1).
This means you'll have to choose a format that supports alpha channels (png, tif, etc.), or you can create masks for your images (much more difficult, as well as performing worse than using an image with alpha).
I'm still a little confused. How would I do it if I want the color pink to appear clear.
Provide adequate context. As it stands, your question could have a gadzillion answers, some of which would involve scissors or acid.
How To Ask Questions The Smart Way
SSCCE : Java Glossary
db
I painted the background of my sprite pink. I want to convert the pink to transparent so it looks like my sprite is walking on the background.
load your image in an application that can edit alpha values (photoshop, gimp, there are some other ones, but MS paint does not support this). Then, everywhere there is a pink pixel you don't want to be visible, use the tool provided by your specific application to change the alpha channel to 0. If you're unsure how to do this, a quick google search should provide this information.
Once you've removed the alpha channel, you need to load the image acknowledging that there are 4 channels (RGBA). TYPE_4BYTE_ABGR will work for this, as will TYPE_INT_ARGB. You should be able to paint the image as normal and the channels marked as having 0 alpha will be completely transparent (or invisible).
Brt93yoda (August 31st, 2010)
Thank you!