如何使Texture2D 50%透明? XNA [英] How to make a Texture2D 50% transparent? XNA

查看:99
本文介绍了如何使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?

推荐答案

假定您使用的XNA 4.0与预乘alpha.在您的spritebatch.draw中,将颜色乘以浮点数,将0.5f乘以50%的透明度,然后像平常一样绘制.如果您不使用预乘alpha,出于性能原因,建议您这样做,并且习惯后会更直观.

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.

示例:

_spriteBatch.Draw(texture, location, Color.White * 0.5f);

还要确保将混合状态设置为BlendState.AlphaBlend或其他支持alpha且不是NonPremultiplied的混合状态.

Also make sure you set your blend state to BlendState.AlphaBlend, or another blend state that supports alpha and is not NonPremultiplied.

示例:

_spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);

这篇关于如何使Texture2D 50%透明? XNA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆