CHAPTER 3 ■ WORKING WITH 2D IMAGES/TEXTURES IN XNA 3.0
192
stringBuilder.Length = 0;
stringBuilder.Append("StringBuilder example: ");
for (int i = 0; i < 10; i++)
stringBuilder.Append(i);
spriteBatch.DrawString(myFont, stringBuilder, new Vector2(50, 180), Color.White
➥
, 0, new Vector2(0, 0), 0.5f, SpriteEffects.None, 0);
The Code
All the code is available for download at www.apress.com.
Your SpriteFont object is initialized in the LoadContent method, together with the SpriteBatch,
which is loaded by default:
protected override void LoadContent()
{
device = graphics.GraphicsDevice;
spriteBatch = new SpriteBatch(GraphicsDevice);
myFont = Content.Load<SpriteFont>("ourFont");
}
These two objects are all you need to render some text in your Draw method: ...