World Mapper (3)

April 16th, 2007

This project continues our initial exploration into creating mapping applications using XNA. Last time we setup the basic application and today we will add some new functionality.

Resizing the Image

I first created a larger background image (800 pixels x 400) to be used for the rest of this project. Two new variables were added:

int mapWidth = 800;
int mapHeight = 400;

…and used in the Initialize Function:

graphics.PreferredBackBufferWidth = mapWidth;
graphics.PreferredBackBufferHeight = mapHeight;


Mouse Object Creation

As discussed in our previous post, we will now start adding objects in our source code. The simple example shown was that of a Mouse object used to store the mouse’s cursor location and button states. So a new file (shMouse.cs) has been added to the project and used in the code to manage the mouse input.

Full Screen

Another benefit to programming with XNA is how easy it is to switch into full screen mode. I added some code in Update function to switch the program into full screen mode when the F key is pressed:

else if (keyState.IsKeyDown(Keys.F))
{
  graphics.ToggleFullScreen();
}

Pressing F again will switch back to windowed mode. Yes, it is that simple.

Summary

Today’s changes were relatively minimal but did introduce several new concepts that are important to our future objectives. Below is a link to download the updated source code. The download also includes the Mouse object model created using Dia.

Download Source Code