2013-12-13 74 views
2

我在我的遊戲中有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; 
} 

然而繪製狀態似乎沒有在XNA 4.0工作之前調用。任何人都知道解決方法?

回答

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可能會有所幫助。

HTH