1
votes

I'm using XNA to visualize some data, and I'm trying to use billboards for data, and spritebatch for HUD text drawing.

For the billboards, I'm using the following example, which works great: http://create.msdn.com/en-US/education/catalog/sample/3d_audio

In that example, there is a cat and dog sprite, where the cat passes in front of or behind the dog, depending on their positions and the camera position as you'd expect. It doesn't matter what order Cat.Draw and Dog.Draw are called in. These guys are drawn from a BasicEffect.

However if I add a class that inherits DrawableGameComponent and uses a SpriteBatch, the BasicEffect in other components loses it's depth sorting and the Quads are drawn in the order called. Note that this component is added to the Game class via this.Components.Add(...).

Is there an incompatibility between BasicEffect and SpriteBatch? The problem occurs whenever SpriteBatch.Begin()/End() is called. If I don't call this the cat/dog render fine.

Any ideas?

1

1 Answers

2
votes

You need to reset some renderstates that SpriteBatch changes.

Try setting these before your basiceffect calls:

GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;

More information about which render states SpriteBatch alters: http://blogs.msdn.com/b/shawnhar/archive/2010/06/18/spritebatch-and-renderstates-in-xna-game-studio-4-0.aspx