<< Chapter < Page | Chapter >> Page > |
I will explain the code in the Game1 class of the project named XNA0132ProjA that produced the screen output shown in reduced form in Figure 4 .
Figure 4 . Demonstration of on-screen text with the Lindsey font.
As usual, I will explain the code in fragments. A complete listing of the Game1 class is provided in Listing 12 near the end of the module.
Here is my interpretation of the coding steps for displaying on-screen text in the game window.
Listing 1 shows the beginning of the Game1 class and the overridden LoadContent method for the project named XNA0132ProjA . This project, which is different from XNA0132Proj to be discussed later, demonstrates how to draw onscreen text.
Listing 1 . Beginning of the Game1 class and the overridden LoadContent method for the project named XNA0132ProjA.
namespace XNA0132ProjA {
public class Game1 : Microsoft.Xna.Framework.Game {GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;SpriteFont Font1;
Vector2 FontPos;//-------------------------------------------------//
protected override void LoadContent() {spriteBatch = new SpriteBatch(GraphicsDevice);
//Create a new SpriteFont object.Font1 = Content.Load<SpriteFont>("Lindsey");
//Create a new Vector2 object to center the text// in the game window.
FontPos = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2,
graphics.GraphicsDevice.Viewport.Height / 2);}//end LoadContent method
Notification Switch
Would you like to follow the 'Xna game studio' conversation and receive update notifications?