Book Image

Building your First Mobile Game using XNA 4.0

By : Brecht Kets, Thomas Goussaert
Book Image

Building your First Mobile Game using XNA 4.0

By: Brecht Kets, Thomas Goussaert

Overview of this book

With the dawn of the Windows Phone 7 platform, Microsoft has offered us an easy way to create 3D mobile games. In this book, we will build a 3D game for Windows Phone 7 together, taking full advantage of the graphics and touch capabilities, along with the sensors of the platform."Building your First Mobile Game using XNA 4.0" is the book for starting game development on the Windows Phone 7 platform. This book will go over the technical aspects of building games along with designing your own framework. Finally we'll build an actual game together from the ground up! This book will set future mobile game developers in the right direction.The XNA framework empowers us to build 2D and 3D games for PC, Xbox 360 and Windows Phone 7. We will use those capabilities to create stunning 3D games for the Windows Phone 7 platform. We will start by covering the basics like drawing graphics, followed by building a custom framework and end with building a game together!In this book, we will cover drawing 2D and 3D graphics, both static and animations. We will also cover the various ways of handling user input and help set the mood of our game playing both 2D and 3D sound, and accessing the user's media library. The only thing left before building a game is covering several techniques created for making our life easier while building the game, whilst building a framework to do just that. Finally, we'll build a 3D game together that will run on the Windows Phone 7 platform."Building your First Mobile Game using XNA 4.0" is the book you need to get started with mobile game development for Windows Phone 7. Its hands on approach will set you on your way in no time. Let's build some games!
Table of Contents (16 chapters)

Getting started with your first application


Let us start by creating our first—empty—application, and deploying it to the emulator or an actual Windows Phone device.

After installing everything, go ahead and open up Microsoft Visual Studio 2010 Express for Windows Phone or your Visual Studio 2010 if you have another version installed.

  1. Go to File | New | Project. The New Project window will pop up as shown in the following screenshot:

  2. Among the installed templates (on the left-hand side of the New Project window) we can find XNA Game Studio 4.0. Click it and select Windows Phone Game (4.0) in the middle of the screen.

  3. At the bottom of the window, we can give our game a proper name and choose a file location for our game. Click on the OK button.

  4. Next we get asked which platform of Windows Phone we want to develop for, that is 7.0 or 7.1. Go ahead and choose Windows Phone OS 7.1 as illustrated in the following screenshot and click on OK.

Note

With Windows Phone OS 7.0, Microsoft means the Windows Phone 7 Mango devices. Windows Phone OS 7.1 means the Windows Phone 7.5 Tango devices.

Now XNA Game Studio created a new project that contains a class called Game1. This is our main game class. Don't worry about the code yet, we will go over this in the next chapters. The important part is that everything is set up for us to begin.

Take a look at the toolbars at the top. There you can find a drop-down menu where we can select what device we want to deploy to.

We can choose between a Windows Phone device, an emulator with 512 MB RAM, and an emulator with 256 MB RAM. The latter aims at the low end devices. Choose Windows Phone Emulator – 512 MB. If you want to deploy to an actual device, choose Windows Phone Device; make sure it is connected to your PC and that the Zune Software is running. The device also needs to be unlocked. During development, it can be wise to make sure the device doesn't lock automatically. This can be done via Settings | Lock + Wallpaper | Screen time out after.

When you press F5, our game will be compiled and then deployed. After everything is loaded correctly, two different screens pop up. With the Additional Tools window, we can simulate the accelerometer, GPS data, and take screenshots. On the phone emulator, we can see an empty, cornflower blue screen.

This might not seem like a lot, but our entire render loop has been made, and we are ready to start loading content and displaying models. Let's get going!