Change run-time transparency transparency on MonoGame

I am very new to the MonoGame library. I am loading a texture from a .xnb file

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

and then I want to change its transparency (alpha) at runtime.

Oh, I found how to do it myself.

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

This line of code will draw a texture with half transparency.

+7
transparency textures monogame
source share
1 answer

You can change the opacity of the texture using (semi) transparent color in the drawing call:

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

Values ​​range from 0 (fully transparent) to 1 (completely opaque). Color has many different constructors , so you can also pass bytes (0-255) instead of float, which will lead to the same thing.

0
source share

All Articles