如何使Texture2D 50% 透明? XNA
我正在使用 SpriteBatch 在屏幕上绘制 Texture2D,并且想知道如何操纵图像的不透明度?有人知道实现这一目标的最佳方法吗?
I'm using SpriteBatch to draw a Texture2D on the screen and was wondering how I could manipulate the the images opacity? Anyone know the best way in accomplishing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您使用带有预乘 alpha 的 XNA 4.0。在 spritebatch.draw 中,将颜色乘以浮点数,0.5f 表示 50% 透明度,然后像平常一样绘制。如果您没有使用预乘 alpha,我建议您出于性能原因使用预乘 alpha,并且在您习惯后它会更直观。
示例:
编辑:
另请确保将混合状态设置为 BlendState.AlphaBlend 或其他支持 Alpha 并且不是 NonPremultiplied 的混合状态。
例子:
Assuming you are using XNA 4.0 with premultiplied alpha. In your spritebatch.draw multiply the color by a float, 0.5f for 50% transparency, and draw as you would normally. If you are not using premultiplied alpha I suggest you do for performance reasons and its more intuitive after you get used to it.
Example:
Edit:
Also make sure you set your blend state to BlendState.AlphaBlend, or another blend state that supports alpha and is not NonPremultiplied.
Example:
只需使用颜色作为
new Color(RGBA);
其中:例如:
Just use color as
new Color(RGBA);
where:For instance: