Time for action – drawing the score

  1. Add a new Vector2 to the declarations area of Game1 to store the screen location where the score will be drawn:
    Vector2 scorePosition = new Vector2(605, 215);
  2. In the Draw() method, remove "this.Window.Title = playerScore.ToString();" and replace the line with:
    spriteBatch.DrawString(pericles36Font,
        playerScore.ToString(),
        scorePosition,
        Color.Black);

What just happened?

Using named vectors to store things like text positions, allows you to easily move them around later if you decide to modify the layout of your game screen. It also makes code more readable, as we have the name scorePosition instead of a hard-coded vector value in the spriteBatch.DrawString() call. Since our window size is set to 800 by 600 pixels, ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.