Question

I'm trying to implement terrain collision in XNA so I've added some dynamic text that allows me to test whether calculations are correct. Everything was rendered just fine until I called:

spriteBatch.Begin(); spriteBatch.End();

or

spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); spriteBatch.End();

With these instructions terrain glitches a little bit, when I remove these two lines from my code everything is back to normal (but it means I cannot draw HUD)

Anyone has any clue what can cause that and how should I fix it?

screens:

with sprite batch on

with sprite batch off

Was it helpful?

Solution

it due to spritebatch change the graphicsdevice states...

before drawing the terrain you should store the right renderstates...

usually the you have to set the right RasterizerState and DepthStencilState.

Common values are RasterizarState.CullNone and DepthStencilState.Default

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top