1
\$\begingroup\$

In MonoGame I am using SpriteBatch to draw sprites. I want to create a semi transparent overlay that would 'tint' the sprite with a given color. SpriteBatch.Draw accepts Color parameter that allows to specify the tint, however the alpha channel seems to make the whole sprite transparent (not the tint only).

To address the problem i am overlaying my sprites with another white, semitransparent sprite tinted to a given color. It works as expected, but I am not sure if that is the correct (and most optimal) approach.

Can you suggest better/faster technique?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

Don't use a color with alpha in the SpriteBatch.Draw(...Color). Your sprite's transparent parts will stay that way, and their opaque parts will be tinted.

\$\endgroup\$
3
  • \$\begingroup\$ sorry maybe I wasnt clear, my sprite is opaque (no transparency), its just when i use SpriteBatch.Draw with eg. Color.Green the tint is too strong, i would like it to be Color.Green with 30% opacity. \$\endgroup\$ Commented Oct 21, 2012 at 8:32
  • \$\begingroup\$ In that case, try using something that is almost white. Like Color(250,255,250) \$\endgroup\$ Commented Oct 21, 2012 at 8:34
  • \$\begingroup\$ thanks! that's a correct answer. Now it seems obvious :) \$\endgroup\$ Commented Oct 21, 2012 at 9:00
1
\$\begingroup\$

"Color.Green the tint is too strong, i would like it to be Color.Green with 30% opacity."

I think you mean saturation, not opacity. Here you go:

Color desaturatedGreen = Color.Lerp(Color.White, Color.Green, 0.3f);
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .