Xna Tutorial 01

Only available on StudyMode
  • Download(s) : 137
  • Published : April 4, 2013
Open Document
Text Preview
Lab 1 – Building a Basic Game
Project XNA 2010 - Phil Ward & Paul Taylor 2010 (Revised by Andrew Herbert 2010) This is the biggest and hardest tutorial you will have to do, it’s a fair bit of work, but once you have finished you will be ready to build heaps of games. What are we building?

THE Color Game – Yes it is spelt wrong, but that is how you’ll need to spell it when you are programming the game! Using your keyboard (and later on an Xbox 360 controller) you need to press the letter (R G B Y) or coloured button on the controller which matches the colour of the screen. By time we have finished three tutorials, you’ll be forcing players to think quickly, and giving them scores, taking away lives, and telling them when the game is over. To start with we will get the screen colour changing, and then start using the keyboard. * Creating a new project

Visual Studio 2008:
Start->All Programs->Microsoft XNA Game Studio 3.1->Microsoft Visual Studio 2008 Select File->New->Project
C# Express:
Start->All Programs->Microsoft XNA Game Studio 3.1->Microsoft Visual C# 2008 Express Edition Select File->New Project

Select the XNA Game Studio 3.1 icon underneath the Visual C# node. A set of available projects will appear in the right pane. Then select the Windows Game (3.1) Icon

Give your project a name (such as PaulsGame) and simple location such as c:\XNA\,and then click on the OK button. This will create the base Object and functions needed to build a game. This will create a basic game for you, and you will be presented with the Visual Studio Interface. On the Right hand side you will see the Solution Explorer

In the middle of the screen you will see the code window, the important things to look at are the Open File Tabs across the top, these will let you change objects very quickly later on, and the Method Selector, which you will be using a lot to find the method you want to edit.

By default the base Object is called Game1, this is the main object of your game. We will use it to create new objects, and to tell the new objects what to do, how to look, and what sounds to make. * Building and Testing your Project

Now we are going to build your project and see what you have made. From the top menu, Click on Build->Build Solution (or press F6).

You will see a little status message in the bottom left of the screen change from Ready to Build Started then finally to Build Succeeded. If anything goes wrong this message will change back to Ready, and you will see the errors appear in the bottom window.

If you double-click on any of the errors Visual Studio will take you to the line of code that is causing the problem. It is always best to start at the top of the error list, and only fix 1 error at a time. After fixing each error, you should always try to build the project again (F6), to make sure that you did actually fix it! Enough boring bits, let’s get your game running. From the top menu, Click on Debug->Start Debugging.

After a short delay you will see your game running, a nice boring blue box. Well, that’s all you have made! Press Escape or click on the X to shut down the Window. Remember to save your work periodically so you don’t lose all your hard work! From the top menu, Click on File->Save All. We can also click on the Save All icon to save our work.

Changing the colour of the screen
Use the method selector and find Draw(GameTime gameTime). Right now this method has a line of code that clears the screen to CornflowerBlue. Yuck! protected override void Draw(GameTime gameTime)


// TODO: Add your drawing code here

As lovely as this colour is, it’s our game, so we will change it. So let’s change the Color.CornflowerBlue part to Color.Red or Color.Blue instead. protected override void Draw(GameTime gameTime)...
tracking img