I have a problem through out my current code where certain Texture2D's are not drawing correctly over each other.

For example, at the start I have sprite font being drawn over a background image and half the text is not shown when I add the image.

        _sb.Draw(_background, new Rectangle(0, 0, 800, 480), Color.White);
        if (isPaused)
            _sb.DrawString(_bigFont, "Resume", new Vector2(295, 200), Color.Black);
        _sb.DrawString(_bigFont, "Start", new Vector2(315, 200), Color.Black);

The text then seems to appear if I change the value of other text on the screen.

Is there something I am missing here?


  • \$\begingroup\$ How are you initializing the SpriteBatch? \$\endgroup\$ – John McDonald Feb 24 '12 at 23:35
  • \$\begingroup\$ spriteBatch = new SpriteBatch(GraphicsDevice); \$\endgroup\$ – boburob Feb 24 '12 at 23:38
  • \$\begingroup\$ spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); \$\endgroup\$ – boburob Feb 24 '12 at 23:38
  • \$\begingroup\$ Can we have a picture? \$\endgroup\$ – ClassicThunder Feb 25 '12 at 0:03
  • \$\begingroup\$ tinypic.com/r/28vef77/5 When I update the something else on the screen the text appears. \$\endgroup\$ – boburob Feb 25 '12 at 0:16

Unless you are actually playing with the Depth, you should be using SpriteSortMode.Deferred. MSDN Doc Here

If you are drawing everything at Depth 0, I'm pretty sure that XNA will pick a draw order for you. There are others discussing a similar issue here: http://forums.create.msdn.com/forums/p/72055/439545.aspx.

In 3D, this is usually called Z-fighting.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.