www.it-ebooks.info Windows Phone 7 XNA Cookbook Over 70 recipes for making your own Windows Phone 7 game Zheng Yang BIRMINGHAM - MUMBAI www.it-ebooks.info Windows Phone 7 XNA Cookbook Copyright © 2012 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: February 2012 Production Reference: 1090212 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84969-120-8 www.packtpub.com Cover Image by John M. Quick (john.m.quick@gmail.com) www.it-ebooks.info Credits Author Zheng Yang Reviewers Ioannis Panagopoulos Elbert Perez Gareth Williams Acquisition Editor Steven Wilding Lead Technical Editor Chris Rodrigues Technical Editors Joyslita D'Souza Arun Nadar Azharuddin Sheikh Copy Editor Laxmi Subramanian Project Coordinator Leena Purkait Proofreader Bernadette Watkins Indexer Monica Ajmera Mehta Graphics Manu Joseph Valentina D'Silva Production Coordinator Melwyn D'sa Cover Work Melwyn D'sa www.it-ebooks.info About the Author Zheng Yang is a hands-on Technical Leader with ve years combined professional experience providing core development engineering for global Microsoft Consumer-Facing Applications and as an independent Game Developer. He is a dynamic, results-oriented developer with a proven history of providing innovative solutions to complex technical problems. When he was a student, he achieved recognition from Microsoft Research Asia and Microsoft Imagine Cup Team. Zheng Yang has advanced technical knowledge of key development technologies including C#, the .NET framework, C++, Visual Studio, DirectX, and SQL Server. He has solid expertise across the full life cycles of both Software Development and Game Production. www.it-ebooks.info About the Reviewers Ioannis Panagopoulos is a Computer Engineer with a PhD in Computer Systems Design specializing in software development for commercial as well as scientic applications. Since 2010, he has also been an MVP for Microsoft. He has participated in many software development projects targeting a vast variety of application domains in collaboration with companies and research facilities. He is also offering consulting services regarding software design and implementation in .NET technologies. He has given lectures in higher education in areas including of operating systems software development and hardware design. He is also an invited speaker in several Microsoft development events. His current software development passions are WPF, ASP.NET MVC, the Entity Framework, XNA in WP7 and HTML5. He lives in Athens, Greece. Elbert Perez is a full-time independent Game Developer working exclusively on Windows Phone using XNA and Silverlight. Elbert has created over 13 games on these frameworks with the majority of them breaking the top 20 downloaded games. www.it-ebooks.info www.PacktPub.com Support les, eBooks, discount offers, and more You might want to visit www.PacktPub.com for support les and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub les available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub.com for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read, and search across Packt's entire library of books. Why Subscribe? f Fully searchable across every book published by Packt f Copy and paste, print, and bookmark content f On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. www.it-ebooks.info www.it-ebooks.info www.it-ebooks.info This book is dedicated to: My parents, Decheng Yang and Guangxiu Shen, for giving me the spirit and belief to pursue my dream. Thanks for always encouraging me to do what I love to do. www.it-ebooks.info [...]... XNA 4.0 for Windows Phone Even if you are relatively new to Windows Phone 7 and XNA 4.0, this chapter should get you up and running Can't wait to begin Windows Phone 7? Let's begin Installing Windows Phone Developer Tools Microsoft XNA Game Studio 4.0 is included as part of the Windows Phone Development Tools It is a set of software tools that can be used by developers to create games for Windows Phone. .. into Windows Phone Developer Tools and XNA Game Studio 4.0 In this chapter, we will cover: ff Installing Windows Phone Developer Tools ff Creating your first Windows Phone XNA application ff Deploying your game on an emulator or device ff Getting familiar with orientation ff Using DrawableComponent and GameServices Introduction Windows Phone 7 is a new platform from Microsoft It succeeds the Windows. .. Contents Preface 1 Chapter 1: Jump into Windows Phone Developer Tools and XNA Game Studio 4.0 7 Introduction 7 Installing Windows Phone Developer Tools 8 Creating your first Windows Phone XNA application 9 Deploying your game on an emulator or device 12 Getting familiar with orientation 15 Using DrawableComponent and GameServices 18 Chapter 2: Playing with Windows Phone Touch and Sensors 23 Chapter 3:... developers to create games for Windows Phone 7, Xbox LIVE Indie Games, and Windows The entire tool package contains: ff Visual Studio 2010 Express for Windows Phone ff Windows Phone Emulator Resources ff Silverlight 4 Tools For Visual Studio ff XNA Game Studio 4.0 ff Microsoft Expression Blend for Windows Phone Installing the toolset is the first step of your Windows Phone XNA game programming journey In this... games around Xbox Live based on XNA Game Studio 4.0 Unlike the previous version, XNA 4.0 is included in a tool collection called Windows Phone Developer Tools utilized for producing Windows Phone games With the tools and Visual Studio 2010, it will be easy to have and employ the Windows www.it-ebooks.info Jump into Windows Phone Developer Tools and XNA Game Studio 4.0 Phone application to the device... Windows Phone XNA application After installing the Visual Studio 2010 and Windows Phone Developer Tools, I am sure you cannot wait to begin your first Windows Phone XNA application In this section, you will start the charming journey, learn about the basic and important code of XNA, and how this code works It is easy to get started 9 www.it-ebooks.info Jump into Windows Phone Developer Tools and XNA Game... the Windows Phone Game project for you 5 The generated Windows Phone Game project WindowPhoneGame1 automatically has the main game functionalities; the other generated associate project WindowsPhoneGame1Content is responsible for the game content: 10 www.it-ebooks.info Chapter 1 How it works The basic methods in Game1 class residing in Game1.cs of your first Windows Phone Game project WindowsPhoneGame1... 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... XNA Windows Phone Game is done, although it is just a blank screen as shown in the following screenshot Isn't it easy? Deploying your game on an emulator or device In the previous recipe, you completed your first XNA Windows Phone Game In this recipe, you will learn more details on how you can deploy your Windows Phone application on the emulator or device Getting ready When you build the Windows Phone. .. orientation The orientation for Windows Phone 7 stands for different directions, landscape or portrait By default, XNA programs for Windows Phone 7 run in landscape mode This recipe discusses how to transcend those defaults and explores other issues involving screen size and events Getting ready The following two screenshots demonstrate the different modes of Windows Phone 7 The image on the left indicates . www.it-ebooks.info Windows Phone 7 XNA Cookbook Over 70 recipes for making your own Windows Phone 7 game Zheng Yang BIRMINGHAM - MUMBAI www.it-ebooks.info Windows Phone. into Windows Phone Developer Tools and XNA Game Studio 4.0 7 Introduction 7 Installing Windows Phone Developer Tools 8 Creating your rst Windows Phone XNA