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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With