Text partially not drawn when using _SpriteBatch.DrawString

I’ve attached an image. I have no idea why, but whenever I render text using spriteFont a good chunk of it doesn’t render. I’d love some insight.

It’s sort of hard to get help to my problem when i show no code to debug and i don’t describe what isn’t working in my picture… ?

1 Like

The picture hides the code :wink:

1 Like

My draw loop is below:

 public override void Draw(GameTime gameTime)
    {
        //Draw
        base.Draw(gameTime);
        switch (GameState.Status)
        {
            case GameStatus.Initializing:
                DrawInitializing(gameTime);
                break;
            case GameStatus.GameOver:
                DrawGameOver(gameTime);
                if (IsDebug) { DumpState(); }
                break;
            case GameStatus.InProgress:
                DrawGame(gameTime);
                if (IsDebug) { DumpState(); }
                break;
            case GameStatus.EnterHighScore:
                DrawHighScore(gameTime);
                break;
            case GameStatus.DisplayInstructions:
                DrawInstructions(gameTime);
                break;
            default:
                break;
        }
    } 

The code to draw the “instructions” which is the text on the blue background is below:

   protected virtual void DrawInstructions(GameTime gameTime)
    {
        var instructions = String.Format("RULES:\r\nGame:{0}\r\n{1}", Info.Title, Info.Instructions);
        
        _spriteBatch.Draw(_popupTexture, new Rectangle(20, 20, Game.GraphicsDevice.Viewport.Width - 40, Game.GraphicsDevice.Viewport.Height - 40), Color.White);
        _spriteBatch.DrawString(DebugFont, instructions, new Vector2(CenterX - 350, CenterY - 350), Color.White,0,new Vector2(0,0),1.0f, SpriteEffects.None, 0.0f);
        
    }

`

The spritebatch is passed in as an argument from the Game class. The Game class draw loop is below:

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);
        _spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
        // TODO: Add your drawing code here

        base.Draw(gameTime);
        _spriteBatch.End();
    }

The text displayed above should not have that massive hole in the middle of the sentence following the word “Standard”…

AAAAAAAND now that I look at my code the SpriteSortMode is BackToFront. Change that to Immediate, boom it works.

Sometimes you need to just explain it to someone else to see what you were missing. Oh well, now I know how to properly submit code blocks :slight_smile:

I recommend sticking to Deferred instead of Immediate. That way SpriteBatch can actually batch draw calls.