Book Image

Windows Phone 7 XNA Cookbook

By : Zheng Yang
Book Image

Windows Phone 7 XNA Cookbook

By: Zheng Yang

Overview of this book

Developing games for Windows Phone 7, a new mobile platform, is your big chance to impact the world of mobile games. The XNA 4.0 for Windows Phone 7 integrates a lot of capabilities from software and hardware for you to create incredible games. The next generation of mobile games will be built by you. Windows Phone 7 XNA Cookbook is the best choice for you to make a game on Windows Phone 7. The book helps you to master the indispensable techniques to create your games using XNA 4.0. From the basics such as animating a 2D sprite and interacting with the customized graphical user interface to the more challenging such as 3D graphic rendering and collision detection. This comprehensive cookbook covers all the essential areas of XNA game development for Windows Phone 7, such as approaches to control the sensors, gestures and typical kinds of cameras. We also have recipes for sprite animation, texture rendering, and graphical user interface development that will give you a powerful tool to work with 2D effects. After this we move onto the more juicy stuff with recipes covering 3D graphic rendering and collision detection, and major ways to improve your loading efficiency. You will also work with Xbox live so you can take your game global. Finally, no mobile game development book would be complete without a look at performance optimization to make your games run faster. Windows Phone 7 XNA Cookbook will equip you with the firepower to rock the game world.
Table of Contents (17 chapters)
Windows Phone 7 XNA Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Preface

Windows Phone certainly held the hot spot at the world-class consumer electronics event, the International CES in January 2012. Microsoft CEO Steve Ballmer said, "The past year has really been about the whole push to build what can clearly be the strong third ecosystem in the smartphone market, with a very differentiated point of view."

In fact, Windows Phone has many strong and compelling specialties in mobile markets People Hub, Live Tiles, Marketplace, and Xbox Live. We believe 2012 2013 will be a remarkable year for Microsoft and Windows Phone.

As a developer, everyone hopes to rock the world by using their creativity. How do we do it? We could write an application, but what kind of application? Games? Why? Well, games are the most dazzling way to grab the attention of, and also to entertain people. Why Windows Phone? Windows Phone provides seamless access to your Xbox Live space and is equipped with handy development tool set to make your game global. How? Read this book!

Windows Phone 7 XNA Cookbook is a unique choice covering everything you need to know to develop games on the Windows Phone. It explains all the core areas of XNA game development for Windows Phone, such as controlling sensors, gestures, and different kinds of cameras. The 2D game development recipes will introduce you to the techniques of sprite animation, texture rendering, and graphical user interface creation. After that, the book moves on to more cutting edge topics, with recipes covering 3D graphic rendering, animation and collision detection, and key methods of improving loading efficiency. As a game development book, you will also find throughout discussions and hands-on examples about performance optimization to make your games run faster. Finally, the book presents all of the steps you need to take to make your games show up in the Marketplace — the world stage of game development. It's your time!

What this book covers

Chapter 1, Jump into Windows Phone Developer Tools and XNA Game Studio 4.0, tells you the background of Windows Phone and how to set up the development environment for building your first Windows Phone game.

Chapter 2, Playing with Windows Phone Touch and Sensors, shows you how to use the basic gestures including tapping, swiping, and dragging. You will also learn the techniques for using the accelerometer.

Chapter 3, Coordinates and View — Your First Step into XNA Game Development on Windows Phone 7, explains how 2D and 3D coordinates work in Windows Phone XNA development and how different types of cameras can be used as view.

Chapter 4, Heads Up Display (HUD) — Your Phone Game User Interface, explains how to work with 2D graphics rendering and demonstrates the essential techniques to make GUI controls, such as buttons, list controls, and so on.

Chapter 5, Content Processing, explains Content Pipeline, which is a very unique technology in XNA. It preprocesses the assets including images, 3D models, audios, and so on; also, you can customize different formats for pre-loading. Content Pipeline accelerates the game asset loading speed and gives you flexibility to define your own content model.

Chapter 6, Entering the Exciting World of 3D Models dives into the mystery 3D world in Windows Phone XNA. You will learn a lot of interesting topics on 3D with examples from model viewing to animation.

Chapter 7, Collision Detection, explains an eternal topic in game development. In this chapter, you will get the core ideas of collision detection for 2D and 3D objects, a little harder but useful, the corresponding examples will make your life easier.

Chapter 8, Embedding Audio in your Game, shows you the methods for adding the audio, music, and sound effects into your game. It also demonstrates how to use the XNA framework to add stereo sound to your game.

Chapter 9, Special Effects, teaches you how to work on the built-in effects such as dual-texture effects and environment mapping. Moreover, you will discover how to render the current screen display onto a texture and use it to make screen transition.

Chapter 10, Performance Optimization — Fast! Faster!, specifically shows you how to make your Windows Phone game run faster. It provides you with hands-on examples and tips you can employ to make sure your game gives the user a seamless experience.

Chapter 11, Launching to the Marketplace, focuses on the process of submitting your application to the Microsoft Marketplace, so that everybody using Windows Phone can download your work. It covers all of the steps required, from preparation to submission.

What you need for this book

  • Microsoft Visual Studio 2010 Professional or Express

  • Windows Phone Developer Tools

  • Microsoft DirectX SDK (June 2010)

Who this book is for

If you are an aspiring programmer with some basic concepts in C# and object-oriented knowledge who wants to create games for Windows Phone, this book is for you. It is also for experienced programmers who want to transfer from Windows or Xbox to the Windows Phone 7 platform. Only basic knowledge of C#, .NET, and Computer Graphics is required.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "Put the code into the LoadContent() method:"

A block of code is set as follows:

// Stop the accelerometer if it’s active.
if (accelActive)
{
try
{
accelSensor.Stop();
}
catch (AccelerometerFailedException e)
{
// the accelerometer couldn't be stopped now.
}
}

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Choose Visual Studio 2010 Express for Windows Phone, and the main page for downloading the tool will show up."

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to, and mention the book title through the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books maybe a mistake in the text or the code we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website, or added to any list of existing errata, under the Errata section of that title.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.