Reputation: 1956
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.
Upvotes: 7
Views: 3651
Reputation: 789
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.
Upvotes: 2