Datasheet

protected override void Initialize()
{
backgroundTexture = content.Load<Texture2D>(“CityGroundSmall”);
sprites = new SpriteBatch(graphics.GraphicsDevice);
base.Initialize();
} // Initialize()
To display the background texture, you have to start the sprite batch and render the texture to your
sprites in the
Draw method:
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.Green);
sprites.Begin();
sprites.Draw(backgroundTexture, Vector2.Zero, Color.White);
sprites.End();
base.Draw(gameTime);
} // Draw(gameTime)
This renders the background texture at the location (0, 0) on top of your green background. With the
color parameter, you can also recolor a sprite, but for now this is not important.
If you press F5, you will now see the result shown in Figure 1-14.
Figure 1-14
19
Chapter 1: Introducing XNA
61286c01.qxd:WroxPro 1/21/08 3:44 PM Page 19