base.Draw(gameTime);
}
private void DrawSprite()
{
for(inti=0;i<5;i++)
_sb.Draw(_sprite, new Rectangle(75 * i, 75 * i, 64, 64), Color.White);
}
Since our viewports and backgrounds are in arrays, they’re easily
accessed in our loop. The code to draw the sprites is exactly the
same for each viewport since, as far as the SpriteBatch object is
concerned, we’re drawing to the entire screen. We also get our clip
-
ping for free, so any drawing we do outside of the viewport is
ignored. We don’t have to worry about not drawing things in the
correct order to prevent rendering outside of the viewport. Ideally
you wouldn’t draw outside of the viewport if you could help it, but if
you do you don’t have to worry about it appearing in the area of one
of the other viewports.
The only downside to this technique is beginning and ending the
SpriteBatch for each viewport. Being able to use the Clear method
of the SpriteBatch means that it’s a lot easier to clear the screen
and we don’t need the textures to do so. If our drawing were a lot
more complicated, it would be even easier than if we were to try to
figure out the drawing for each area. Everything would have to be
offset using the Rectangle for each area, which would get messy
after a while.
2D Shooter Game Version 1
At long last we’ve got all the tools in our coding toolbox to create
the first version of our ghost shooting game. Let’s start our final
project for this chapter. We’re going to build on the Game State
Management sample that we looked at in the previous chapter.
Go ahead and open the project. We’ll remove some things we’re
not going to use to get it down to a basic project. Follow these
steps:
1. First off, delete the BackgroundScreen.cs file in the Screens
folder. The easiest way to get rid of the references to it is to
96 Chapter 3

Get Essential XNA Game Studio 2.0 Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.