Game Development Reference
In-Depth Information
spriteScale = Matrix.CreateScale(inputHelper.Scale.X, inputHelper.Scale.Y, 1);
The only thing left to do now is tell the
SpriteBatch
object that we want it to apply
a scaling factor to all the drawing operations. We can do this by calling another
version of the
Begin
method that takes a few different parameters, one of them being
the scale that we want to apply. We do this in the
Draw
method of the
JewelJam
class:
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteSortMode.Deferred,
null
,
null
,
null
,
null
,
null
, spriteScale);
spriteBatch.Draw(...);
Now, our sprites will be nicely scaled in fullscreen mode.
13.6 Making Sure We Can Still Quit the Game
If a game is in fullscreen mode, we have no more means to close the program, except
by force using the Windows task manager. Clearly, this is not really a desirable
'feature' of our game, so let us add a simple extension that will allow us to press the
Escape button to quit the game. In order to do that, we add the following lines to the
Update
method:
if
(inputHelper.KeyPressed(Keys.Escape))
this
.Exit();
Furthermore, we would like to be able to easily switch between windowed mode and
fullscreen mode by pressing the F5 key. In order to do this, we add the following
if
instruction to the
Update
method:
if
(inputHelper.KeyPressed(Keys.F5))
SetFullScreen(!graphics.IsFullScreen);
Now we are done. In the
JewelJam1
program, you can see the complete code. In the
next section, we will expand the
JewelJam1
program to draw a grid of game objects.
13.7 What You Have Learned
In this chapter, you have learned:
•
how to retrieve and set the screen resolution;
•
how to display a game in fullscreen mode;
•
how to scale sprites and correct the mouse position.