views:

118

answers:

3

I am working on a pong clone, and i want to display the player scores onscreen. I don't know how to display it.

+7  A: 

The SpriteBatch object has a DrawString method that takes:

  • a SpriteFont which can be created in your content project and loaded via content.Load
  • the string you wish to write to the screen
  • a Vector2 of the position that you want to draw the text at
  • the Color you wish the text to be.

So for example your draw method might look like this:

public void Draw()
{
    spriteBatch.Begin();

    DrawPaddles(spriteBatch);
    DrawBall(spriteBatch);

    // this being the line that answers your question
    spriteBatch.DrawString(scoreFont, playerScore.ToString(), new Vector2(10, 10), Color.White);

    spriteBatch.End();
}

See http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.drawstring.aspx

Sekhat
+3  A: 

You should start your XNA journey at the XNA Creators Club. Even the most basic tutorials output text.

The XNA Forums are a better resource for XNA-related questions.

Tergiver
+1  A: 

MSDN has you covered: How To: Draw Text

Andrew Russell