Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Sprite Sheet pink color as alpha ?  (Read 2899 times)
0 Members and 1 Guest are viewing this topic.
Offline PixelDeBurner

Junior Member


Medals: 1



« Posted 2012-09-02 19:47:03 »

Hi Everyone. I was watching Notch's coding ( Prelude of the chambered ), and I saw that in his spritesheet there is pink color, but he's using it as alpha.

How does he do that Huh
Offline MindOfCorruption97

Senior Newbie





« Reply #1 - Posted 2012-09-02 19:50:16 »

It isn't necessary actually. What graphics program do you use to create sprites? I recommend paint.net. Just delete the White layer and create a transparent background.

Chaos is Beatiful...
For without Chaos the world will never spin...
Offline PixelDeBurner

Junior Member


Medals: 1



« Reply #2 - Posted 2012-09-02 19:51:11 »

I know that, but I'm just curious.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Rorkien
« Reply #3 - Posted 2012-09-02 20:00:28 »

Well, since the game loads the images as pixel-array, he can just check if the pixel's color is pink and ignore it:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
   public static Bitmap loadBitmap(String fileName) {
         [...]
         for (int i = 0; i < result.pixels.length; i++) {
            int in = result.pixels[i];
            int col = (in & 0xf) >> 2;
            if (in == 0xffff00ff) col = -1;
            result.pixels[i] = col;
         }
         [...]
   }


Quote
if (in == 0xffff00ff) col = -1;

If the color is pink, it will be set as -1 which java counts as transparent
Offline PixelDeBurner

Junior Member


Medals: 1



« Reply #4 - Posted 2012-09-02 20:02:22 »

Thanks !
Online ra4king

JGO Kernel


Medals: 345
Projects: 2
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-09-03 01:11:35 »

"(in & 0xf) >> 2" what's the point of this? You are only keep the rightmost 4 bits if they are 1, then shifting them....?

-1 is fully opaque and fully white on the ARGB scale.....

Offline sproingie

JGO Kernel


Medals: 202



« Reply #6 - Posted 2012-09-03 01:30:50 »

Because if he doesn't mask first, he'll shift in non-zero bits.
Offline jonjava
« Reply #7 - Posted 2012-09-03 04:31:33 »

"(in & 0xf) >> 2" what's the point of this? You are only keep the rightmost 4 bits if they are 1, then shifting them....?

-1 is fully opaque and fully white on the ARGB scale.....

It doesn't make much sense to me either.

It takes the first 4 least significant bits (rightmost) and then shifts them to the right by 2 bits (effectively erasing the first 2 bits) so that you end up with the third and fourth bits from the Blue color at the beginning of the int. The resulting data that is saved into the variable "col" will be '000000000000000000000000000000xx' where 'xx' is the third and fourth bits from the blue color. The following if statement "in == 0xffff00ff)" will always return false.

Because if he doesn't mask first, he'll shift in non-zero bits.


Actually, you always shift in bits of zero.

1  
2  
3  
<<      Signed left shift // Always shifts in 0's from the right.
>>      Signed right shift // Shifts in copies of the MSB (left most bit) from the left.
>>>     Unsigned right shift // Always shifts in 0's from the left.



Just check the resulting pixel for the pink color. And if you've got Alpha enabled (most likely) make the pixel completely transparent (Set leftmost 8 bits to 0). Or if you're not using Alpha you need to omit drawing the specified pixel on the screen altogether.

1  
2  
3  
int col = result.pixels[i];
if (col == Color.pink.getRGB()) col = 0; // Sets all the bits to 0, including the Alpha in ARGB.
result.pixels[i] = col;


Some more random bit manipulation posts.
http://www.java-gaming.org/topics/transparent-colors/26829/msg/238451/view.html#msg238451
http://www.java-gaming.org/topics/tile-rendering/27088/msg/241432/view.html#msg241432

Offline Damocles
« Reply #8 - Posted 2012-09-03 06:28:29 »

Pink/Megenta ist btw classically used to mark transparent parts.

Since its a "spare" color, not usually not used in Artwork, and easy to recognize.
(full red and blue, 0 green channel)

You can use any other spare color too for that purpose, if magenta looks
too ugly when editing the spritesheet.

Offline davedes
« Reply #9 - Posted 2012-09-03 06:45:34 »

Almost always it is better to just save the PNG/GIF with transparency...

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Damocles
« Reply #10 - Posted 2012-09-03 06:48:04 »

Well, this comes from the times, when images (like BMPs) where used
without alpha channel, or when there was just a limited colorpalette, to save size and have better compression.

Not that long ago actually, (100kB heap memory JavaME games etc...)

Offline Best Username Ever

Junior Member





« Reply #11 - Posted 2012-09-03 14:18:01 »

When you're using images with a palette based color format, then one color is dedicated to full transparency. It's sort of like green screen for sprites. By convention, it's pink (#FFFF00) to avoid conflicts with color is more likely to be included in the palette. It could also have been black, grey, white, bright green, etc. but that colors probably the least likely to appear in most sprites. GIMP and other image editors that can handle alpha channels show a background pattern instead of a solid background replacement color.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (23 views)
2014-08-19 09:29:53

Tekkerue (22 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (57 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (29 views)
2014-08-08 02:01:56

Norakomi (36 views)
2014-08-06 19:49:38

BurntPizza (66 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!