如何使用XNA在C#中显示数字和文本?

Sla*_*ard 2 c# xna

我正在制作一个乒乓球克隆,我想在屏幕上显示玩家得分.我不知道如何显示它.

Sek*_*hat 12

该SpriteBatch对象有一个DrawString方法:

  • a SpriteFont可以在您的内容项目中创建并通过content.Load加载
  • 在string你想写信给屏幕
  • a Vector2要在其中绘制文本的位置
  • 在Color您希望的文本设置.

例如,您的draw方法可能如下所示:

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();
}
Run Code Online (Sandbox Code Playgroud)

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