Reputation: 1031
I am working on a pong clone, and i want to display the player scores onscreen. I don't know how to display it.
Upvotes: 2
Views: 11841
Reputation: 4479
The SpriteBatch
object has a DrawString
method that takes:
SpriteFont
which can be created
in your content project and loaded
via content.Load string
you wish to write to the
screen Vector2
of the position
that you want to draw the text atColor
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
Upvotes: 12
Reputation: 14517
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.
Upvotes: 4