我的游戏中有3D模型,但当我通过spritebatch向屏幕添加文本时,模型会消失/变得透明。
我四处寻找解决方案,发现如果在绘制对象之前调用,这应该可以工作
void prepare3d()
{
GraphicsDevice.RenderState.DepthBufferEnable = true;
GraphicsDevice.RenderState.AlphaBlendEnable = false;
GraphicsDevice.RenderState.AlphaTestEnable = false;`
GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;
}
然而,RenderState似乎在XNA 4.0上不起作用。有人知道变通办法吗?
对于XNA 4.0,您可以尝试以下操作:
void prepare3d()
{
//set the depth buffer state
DepthStencilState depthBufferState = new DepthStencilState();
depthBufferState.DepthBufferEnable = true;
GraphicsDevice.DepthStencilState = depthBufferState;
//set the BlendState
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;
}
此链接可能会有所帮助。
HTH