2
votes

Hi I'm trying to follow an answer about making part of a texture transparent when using Alpha Blending from this question The only problem is that this only works in XNA 3.1 and I'm working in XNA 4.0 so stuff like RenderState doesn't exist in the same context, and I have no idea where to find the GfxComponent class library.

I still want to do the same thing as in the example question, a circular area radiating from the mouse position that makes the covering texture transparent when the mouse is hovering over it.

1
Personally I'd use a pixel shader, to which you pass your mouse position, to add the transparency when you draw the original texture. You could also do various blending trickery. Or you could go via a render target.Andrew Russell

1 Answers

2
votes

3.5

GraphicsDevice.RenderState.AlphaBlendEnable = true;

4.0

GraphicsDevice.BlendState = BlendState.AlphaBlend;

See Shawn Hargreaves post for more info: http://blogs.msdn.com/b/shawnhar/archive/2010/06/18/spritebatch-and-renderstates-in-xna-game-studio-4-0.aspx

EDIT: In the post you can see Shawn using BlendState. You create a new instance of this, set it up however you like, and pass this to the graphics device. Like so:

BlendState bs = new BlendState();
bs.AlphaSourceBlend = Blend.One;
bs.AlphaDestinationBlend = Blend.Zero;
bs.ColorSourceBlend = Blend.Zero;
bs.ColorDestinationBlend = Blend.One;
bs.AlphaBlendFunction = BlendFunction.Add;
graphicsDevice.BlendState = bs;

That clearer?