MonoGame-BlendState-2D SpriteBatch [英] MonoGame - BlendState - 2D SpriteBatch
问题描述
我需要SpriteBatch
来呈现在WPF或普通UIKit应用中所期望的图像:
I need SpriteBatch
to render images how I would expect in WPF or a normal UIKit app:
-
如您所料,
- 部分透明的PNG会相互渲染
- 我有一个可以修改的Alpha,最好是使用
Color.White
并修改A
值的东西.
- partially transparent PNGs render on top of one another, as you would expect
- I have an alpha I can modify, preferably something like using
Color.White
and modifying theA
value.
最近的一直在使用BlendState.NonPremultiplied
,但是我得到了奇怪的线条,其中部分透明的PNG彼此重叠.
Closest has been using BlendState.NonPremultiplied
, but I get weird lines where partially transparent PNGs overlap on one another.
我在Windows (请参阅此处)上遇到了类似的问题,但是通过更改进行了修复XNA内容项目中的Premultiplied
设置.我该如何为MonoGame做类似的事情? (我希望这里的OpenGL有区别)
I was having similar issues on Windows (see here), but fixed it by changing the Premultiplied
setting in the XNA content project. How can I do similar for MonoGame? (I'm expecting there is a difference in OpenGL here)
推荐答案
我们通过使用两种不同的设置解决了该问题.
We solved it by using two different setups.
在Windows和XNA上:
On Windows and XNA:
- 使用
BlendState.NonPremultiplied
- 在所有PNG的内容项目上将默认设置更改为Premultiply = False
- 要修改精灵的Alpha值,请使用
Color.White
并设置A
值
- Use
BlendState.NonPremultiplied
- Change the default setting to Premultiply = False on the content project for all PNGs
- To modify Alpha value of a sprite, use
Color.White
and setA
value
在MonoGame和iOS上:
On MonoGame and iOS:
- 使用
BlendState.AlphaBlend
- 按原样保留PNG
- 要修改精灵的Alpha值,请使用
Color.White * (float)Alpha / (float)byte.MaxValue
- Use
BlendState.AlphaBlend
- Leave PNGs as-is
- To modify Alpha value of a sprite, use
Color.White * (float)Alpha / (float)byte.MaxValue
我的PNG没有预先乘以 ,它们的使用方式与您从Photoshop中获得的期望值完全相同.
My PNGs are not pre-multiplied and are used exactly as you'd expect coming out of Photoshop.
这篇关于MonoGame-BlendState-2D SpriteBatch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!