Getting Started with the Base Application
Getting Started with XNA and your first Windows Game is really easy; the first stage is to download the Visual Studio C# Express IDE, XNA Game Studio Express, and any service pack releases. Once this has been done and installed you are ready to roll.
XNA Development Center on MSDN
XNA Game Studio Express Home Page
Visual Studio C# Express Download Page
With most programming languages and Systems you generally have to start at the beginning, well it is the same with XNA and Game Studio Express. In the case of XNA your first application is just a Base Windows Game that runs and displays a cornflower blue screen.
Start your project by opening up the Game Studio Express IDE system and select the windows Game Project. Make sure that when you do this that you change the path to a location where you would store your projects, as well as changing the name of the project to something that relates to the project at hand. For the purpose of this article and the next few call the project BaseWindowsGame.
When the IDE has finished working you will be presented with the Base Application Framework that you will use for all of your projects moving forward. To execute, compile or run the project you can either press the Green play button from the main toolbar, press the F5 key or select Start Debugging from the Debug menu. Doing this will compile your application into Debug mode, if you have finished debugging and want to release the project you should make sure that you compile or build your application in release mode.
At this point the Application is finished, but what I will do now is go through some of the basic changes that can be made to this base application.
Changing the Windows Title
When the default application starts the Windows Title for the form is automatically set to the Programs Name. To change this add the following line of code to the Constructor for the main game class.
this.Window.Title = “Application Title”;
Turning the Mouse on
The base or Default behavier for the mouse in an XNA Game Studio Express Application is to have the default mouse cursor invisable. To turn the mouse on and make the cursor visable you need to add the following line of code to the game constructor.
this.IsMouseVisible = true;
Creating a Way Out
When you install and configure the Base Application, the system is configured to allow the game to exit by pressing the Back key on the Xbox 360 Controller. But what if you do not have a controller?
Here are some simple instructions on how to add some basic Keyboard support and have the Application exit when the Escape Key is pressed. I have also left the Controller code in so that the system can be used with both interfaces.
Note that some the information here has been adapted from the XNA Documentation that is included with the Game Studio Express Install.
To get started add the following line just after the creation of the Content and Graphics Device Managers.
The next stage is to set up the initial state of the Keyboard, do this by adding the following line of code the games constructor.
oldState = Keyboard.GetState();
The Last step is to change the update code so that we can detect the Escape Key pressed and exit the application. Change the Update call in the application so that it now has the following code instead of the normal call to the Controller State.
KeyboardState newState = Keyboard.GetState();
// Allows the default game to exit on Xbox 360 and Windows
if ((GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) || (newState.IsKeyDown(Keys.Escape)))
oldState = newState;
Any way that is it for now. I will be trying to post more over the next few days, hope this helps someone….
Cross Post from Virtual Realm – Mykre’s Space