I know I can take a color and multiply it by a float to reduce its alpha like that:

Color color = Color.Green * 0.15f;

But how do I return the color's alpha to it's original value?

I tried doing this:

color.A = 255;

But it seems like I get a different color. (The RGB are different then those of the original color).

Also, just changing the alpha of the original color (directly, not by multiplying) doesn't make it transparent..

  • 1
    \$\begingroup\$ Divide by the same amount. \$\endgroup\$ – Vaughan Hilts Aug 14 '13 at 13:47
  • \$\begingroup\$ It isn't possible to divide for some reason.. \$\endgroup\$ – Ofir Aug 14 '13 at 14:18
  • \$\begingroup\$ @Ofir See how msdn.microsoft.com/en-us/library/… has an op_Multiply function? This is why color * float works. There is no op_Division but this should work color = color * (1 / .15). \$\endgroup\$ – ClassicThunder Aug 14 '13 at 14:32
  • \$\begingroup\$ How silly - but yes, just use inverted mulitplication. Thanks @ClassicThunder \$\endgroup\$ – Vaughan Hilts Aug 14 '13 at 14:38
  • \$\begingroup\$ It works but It's not 100% accurate. Thanks anyway, I'll just do it in another way. \$\endgroup\$ – Ofir Aug 14 '13 at 14:41

You are multiplying all color components, not only the alpha channel (Color.Green * 0.15f;) To only change the alpha:

Color color = Color.Green;
color.A *= 0.15f;
  • \$\begingroup\$ This is wrong because it is not taking into account the fact that he is using XNA and thus premultiplied alpha. \$\endgroup\$ – ClassicThunder Aug 14 '13 at 12:28
  • \$\begingroup\$ Like I wrote in my post, directly changing the alpha doesn't make the object transparent. \$\endgroup\$ – Ofir Aug 14 '13 at 12:40
  • \$\begingroup\$ -1 because Xna uses premultiplied alpha \$\endgroup\$ – Blau Aug 14 '13 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.