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)

Developing for Windows Phone


Let us start by talking about the Windows Phone platform itself. All Windows Phone devices have minimum sets of hardware they have to comply with. This includes three buttons: start, search, and back, a resolution of 480x800, a touch screen, an accelerometer, and more. The list of specifications can be found at http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff637514(v=vs.92).aspx.

With the launch of Windows Phone 7 back in 2010, Microsoft offered two possible ways to develop applications for Windows Phone. The applications we write must be developed using either Silverlight or XNA Game Studio 4.0. Both Silverlight and XNA are powered by the .NET framework. This means we can develop apps for Windows Phone using managed programming languages such as C# (version 3). This book will only cover XNA development, as this framework is very suitable for developing games. We won't be discussing Silverlight.

But first, what is XNA? XNA is a managed framework which runs on top of the .NET framework. It enables us to build games for Windows, Xbox 360, and Windows Phone, with limited adaptations to the source code when switching to another platform. Because it runs on top of the .NET framework, you can use VB.NET or C# as programming languages. In this book, we will use C# and won't cover VB.NET.

What makes XNA interesting in terms of game development is that it takes care of the boring stuff (initializing and maintaining the graphics device and setting up your render loop for instance) for us; this enables us to skip the boiler plate code and focus on the interesting part, being our game.

XNA Game Studio 4.0—the development environment for XNA—is part of the Windows Phone SDK. This toolset is an extension for Visual Studio 2010, and is available for free. Using XNA Game Studio 4.0, you can develop XNA games for Windows Phone (amongst others), and deploy to an emulator or an actual Windows Phone device. However, when you want to deploy to an actual device, the device has to be registered. To register your Windows Phone, you need a valid Dev Center Developer account, which costs $99 annually—unless you are a student. Students can get a free (limited) developer account through www.dreamspark.com. A valid Dev Center Developer account will enable you to create games for and deploy them to Windows Phone. This does not include deploying to Xbox 360.

Installing the Windows Phone SDK

Let us start by installing all the software we need. XNA Game Studio 4.0 (our development environment) is part of the Windows Phone SDK. You can download the latest version from https://dev.windowsphone.com/en-us/downloadsdk. At the time of writing, the most recent version is 'Windows Phone SDK 7.1'. The setup will install the following applications:

  • Microsoft Visual Studio 2010 Express for Windows Phone

  • Windows Phone Emulator

  • Windows Phone SDK Assemblies

  • Windows Phone SDK Extensions for XNA Game Studio 4.0

  • Microsoft Expression Blend SDK for Windows Phone

  • Silverlight 4 SDK and DRT

  • WCF Data Services Client for Windows Phone

  • Microsoft Advertising SDK for Windows Phone

Note that all these applications will enable you to build applications for Windows Phone 7.0 and Windows Phone 7.5. The tools we will use are the Windows Phone Emulator and XNA Game Studio 4.0.

When you already have a version of Visual Studio 2010 installed (Professional for instance), the add-ins for this version will be installed automatically. Make sure you have all service packs installed for that installation version.

After installing the SDK, make sure you install the latest update. This can be downloaded from the same location as the SDK. At the time of writing, the latest update is 'Windows Phone SDK 7.1.1 Update'.

Registering your Windows Phone

To be able to deploy games to our Windows Phone, we need to register the device. There are three prerequisites:

  • Obtain a Microsoft account if you don't have one. This can be done through www.live.com.

  • Create a valid Dev Center Developer account (if you don't have one). This can be done through https://dev.windowsphone.com/en-us/join. An Dev Center Developer account costs $99 annually, and it will enable you to deploy games to Windows Phone.

  • If you are a student, you can register for free using a valid DreamSpark account. Go to www.dreamspark.com to register. Your university/school representative can help you out here.

  • Install Zune from www.zune.net.

Once the above is taken care of, we can start registering our Windows Phone. Start by making sure that the date and time are correct and connect your phone to your PC using the USB cable. Zune will start automatically. If it does not start, we need to start it ourselves. If everything went okay, the phone will appear in the 'Device' tab of the Zune software. On the first run, this might take a few minutes, while Windows installs the drivers for the phone.

Next we can open the Windows Phone Developer registration tool we can find by clicking Start | All Programs | Windows Phone SDK 7.1. Once the application has started, you should see the following window:

Once the status says Phone ready, register using your Microsoft account.