Sign in to follow this  
emforce

HUD transparency

Recommended Posts

emforce    191
Hi guys I was wondering if there was a way of making a transparent HUD for an XNA game? I was thinking it could have something to do with the actual image itself, but I am not sure how to go about it. Any help on the matter would be appreciated!

Share this post


Link to post
Share on other sites
Andy474    694
Well, what you need to do is create a texture with colours of set Alpha transparency.


Texture2D CopyTransTexture(GraphicsDevice device, Texture2D Texture, float Alpha)
{
//2 Color[]
//This one is kept empty
Color[] HolderColors = new Color[Texture.Width * Texture.Height];
//We use this to store the colors of out Texture
Color[] colorData = new Color[Texture.Width * Texture.Height];

//Get the Color Data from our Texture
Texture.GetData<Color>(colorData);

//Assign these to out holder Array
for (int i = 0; i < colorData.Length; i++)
HolderColors[i] = new Color(colorData[i], Alpha);

//Create a new Texture from the Colors with set alpha
Texture2D holder = new Texture2D(device, Texture.Width, Texture.Height, 1, TextureUsage.None, SurfaceFormat.Color);
holder.SetData<Color>(HolderColors);
//And return it
return holder;
}




This simple functions takes a texture and recreates it with a set Alpha Value

N.B I just rustled this up so i'm not sure if it will work, theoretically it should. Any problems plz reply xD

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this