小编Dan*_*use的帖子

XNA Alpha Blending使纹理的一部分透明

我想要做的是在XNA中使用alpha混合使绘制的纹理的一部分透明.例如,我将屏幕清除为某种颜色,让我们说蓝色.然后我绘制一个红色的纹理.最后,我绘制的纹理只是一个径向渐变,从中心的完全透明到边缘的完全黑色.我想要的是之前绘制的红色纹理在与径向渐变纹理相同的位置是透明的.所以你应该能够通过红色纹理看到蓝色背景.

我认为这会奏效.

GraphicsDevice.Clear(Color.CornflowerBlue);

spriteBatch.Begin(SpriteBlendMode.None);
spriteBatch.Draw(bg, new Vector2(0, 0), Color.White);
spriteBatch.End();

spriteBatch.Begin(SpriteBlendMode.None);

GraphicsDevice.RenderState.AlphaBlendEnable = true;
GraphicsDevice.RenderState.AlphaSourceBlend = Blend.One;
GraphicsDevice.RenderState.AlphaDestinationBlend = Blend.Zero;
GraphicsDevice.RenderState.SourceBlend = Blend.Zero;
GraphicsDevice.RenderState.DestinationBlend = Blend.One;
GraphicsDevice.RenderState.BlendFunction = BlendFunction.Add;

spriteBatch.Draw(circle, new Vector2(0, 0), Color.White);
spriteBatch.End();

GraphicsDevice.RenderState.AlphaBlendEnable = false;
Run Code Online (Sandbox Code Playgroud)

但它似乎忽略了我所有的RenderState设置.我也尝试将SpriteBlendMode设置为AlphaBlend.它融合了纹理,但这不是我想要的效果.

任何帮助,将不胜感激.

xna

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

xna ×1