简体   繁体   English

C#XNA如何更改整个Texture2D的alpha?

[英]C# XNA How to change the alpha for an entire Texture2D?

是否可以永久更改纹理的alpha值而不将其渲染到另一个表面?

You could use Texture2D.GetData<Color>() and Texture2D.SetData<Color>() and overwrite the alpha value. 您可以使用Texture2D.GetData<Color>()Texture2D.SetData<Color>()并覆盖alpha值。

Edit: 编辑:

This method could be a bit tricky when using Textures with premultiplied alpha. 使用具有预乘alpha的纹理时,此方法可能有点棘手。

If you need to change the transparency in game simply multiply Color.White by the amount you want it to be transparent. 如果您需要更改游戏中的透明度,只需将Color.White乘以您希望透明的数量。 This has almost no additional overhead as the pixels color values are already being multiplied by what color you pass into the draw function. 这几乎没有额外的开销,因为像素颜色值已经乘以您传递到绘制函数的颜色。 Its simply 1 additional flop per loop. 它每循环只需1次额外的翻牌。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM