7

I am very new with MonoGame library. I load a texture from .xnb file

_background = content.Load<Texture2D>(_backgroundKey);

and then i want to change it transparancy(alpha) at the runtime.

Oh i found how to do it myself

spriteBatch.Draw(texture, position, sourceRect, Color.White * 0.5f, .......);

This line of code will draw the texture at half transparency.

EternalHour
  • 8,308
  • 6
  • 38
  • 57
igorGIS
  • 1,888
  • 4
  • 27
  • 41

1 Answers1

2

You can change the opacity of a texture by using a (semi-)transparent color in the draw call:

spriteBatch.Draw(texture, position, new Color(Color.Pink, 0.5f);

The values range from 0 (completely transparent) to 1 (completely opaque). Color has a lot of different constructors, so you can also pass a byte (0-255) instead of a float, which will result in the same thing.

jalgames
  • 781
  • 4
  • 23