Writing Your First Game (XNA Game Studio 4.0 Programming)

Now that you have installed the tools and set up your Xbox 360 and Windows Phone 7 device, you are ready to create your first game. The first game we create is the default template for the three different game types.When you create a new project, a new class inherits from Microsoft.Xna.Framework.Game.This is your game class and overrides some important methods that you will use. For example, a LoadContent method loads all of the game content.An Update method run each frame is where you should handle updating objects and reading user input.A Draw method, by default, clears the screen to a solid color called CornflowerBlue.

Your First XNA Game Studio Windows Game

To create your first XNA Game Studio Windows Game, you need to first open Visual Studio.To create the new project, select File, and then select New Project. In the left column, be sure to select XNA Game Studio 4.0, which is under the Visual C# tree.You can see the number of projects that you can create. Select the Windows Game (4.0) project, give it a name, and click the OK button.

The new project opens to the generated new Game class.You can now run the game by pressing the F5 key. You should see a solid light blue window display. You can press the Escape key or click the Close button on the window to exit the game.

That’s all there is to it.You have created your first XNA Game Studio Windows game.

Your First XNA Game Studio XNA Xbox 360 Game

Now let’s create your first XNA Game Studio Xbox 360 game. Just like before, select the File, New Project menu in Visual Studio. Select the Xbox 360 Game (4.0) project, give it a name, and click OK.


The new project opens to the Game class. If you have XNA Game Studio Connect running, you can start the game by pressing F5.

Again, you can see your game run on the Xbox 360, a light blue screen. Pressing the Back button on the controller exits the game back to XNA Game Studio Connect.

You have now built your first XNA Game Studio Xbox 360 game and run it in on the console.

Your First XNA Game Studio Windows Phone 7 Game

Finally, let’s create a Windows Phone game. Go to File, New Project in Visual Studio. In the New Project dialog, select the Windows Phone Game (4.0) project, give it a name, and click the OK button.

You can run your Windows Phone games on both the Windows Phone 7 Emulator and on the physical Windows Phone 7 device.There is a drop-down selector in the upper left of the tool bar in Visual Studio that enables you to select which to use.

Select Windows Phone 7 Emulator from the drop-down menu and press F5.This launches the Windows Phone 7 Emulator and starts your game. Pressing the Back button on the emulator exits your game but the emulator continues to run.You can leave the emulator running between debugging sessions to speed up your development process.

Now select Windows Phone 7 Device from the drop-down menu in Visual Studio and press F5. If you have your Windows Phone 7 device connected and registered, the game launches on your device showing the light blue screen. Pressing the hardware Back button exits your game.

Next post:

Previous post: