我的游戏中有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;
}
此Link可能会有所帮助。
高温超导