Sams Teach Yourself Windows Phone 7 Game Programming in 24 Hours
Jonathan S. Harbour
800 East 96th Street, Indianapolis, Indiana, 46240 USA
Sams Teach Yourself Windows Phone 7 Game Programming in 24 Hours
Copyright 2012 by Sams Publishing
All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from the use of the information contained herein.
ISBN-13: 978-0-672-33554-9
ISBN-10: 0-672-33554-9
Editor-in-Chief
Greg Wiegand
Executive Editor
Neil Rowe
Development Editor
Mark Renfrow
Managing Editor
Kristy Hart
Project Editor
Andrew Beaster
Copy Editor
Cheri Clark
Indexer
Ken Johnson
Proofreader
Sarah Kearns
Technical Editor
Jim Perry
Publishing Coordinator
Cindy Teeters
Book Designer
Gary Adair
Composition
Nonie Ratcliff
Library of Congress Cataloging-in-Publication Data is on file.
Printed in the United States of America
First Printing November 2011
Trademarks
All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an as is basis. The author and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book.
Bulk Sales
Sams Publishing offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales. For more information, please contact
U.S. Corporate and Government Sales
1-800-382-3419
For sales outside of the U.S., please contact
International Sales
Dedication
Dedicated to FASA Corporation founders Jordan Weisman
and L. Ross Babcock III, whose games continue to inspire.
Table of Contents
About the Author
Jonathan S. Harbour has been programming video games since the 1980s. His first game system was an Atari 2600, which he played with, disassembled, on the floor of his room as a kid. He has written on numerous subjects such as C++, C#, Basic, Java, DirectX, Allegro, Lua, DarkBasic, Pocket PC, and game consoles. He is the author of another recent book titled XNA Game Studio 4.0 for Xbox 360 Developers. He holds a Masters degree in Information Systems Management. Visit his web log and game development forum at www.jharbour.com/forum, and his Facebook page at www.facebook.com/jharbourcom.
Acknowledgments
Thank you to the editorial staff at Sams for their hard work in getting this book polished and into print: Neil Rowe, Mark Renfrow, Andy Beaster, Cheri Clark, Ken Johnson, Sarah Kearns, Nonie Ratcliff, and a special thanks to Jim Perry for his technical advice. I enjoyed working with all of you and hope we can do it again soon.
We Want to Hear from You!
As the reader of this book, you are our most important critic and commentator. We value your opinion and want to know what were doing right, what we could do better, what areas youd like to see us publish in, and any other words of wisdom youre willing to pass our way.
You can email or write me directly to let me know what you did or didnt like about this bookas well as what we can do to make our books stronger.
Please note that I cannot help you with technical problems related to the topic of this book, and that due to the high volume of mail I receive, I might not be able to reply to every message.
When you write, please be sure to include this books title and author, as well as your name and phone or email address. I will carefully review your comments and share them with the author and editors who worked on the book.
Email:
Mail: Neil Rowe
Executive Editor
Sams Publishing
800 East 96th Street
Indianapolis, IN 46240 USA
Reader Services
Visit our website and register this book at www.samspublishing.com/register for convenient access to any updates, downloads, or errata that might be available for this book.
Introduction
This book was written with the beginner in mind. Each of the 24 hours in this book is short and succinct, usually teaching one basic subject and building on previous hours. The subjects covered in this book are geared primarily toward rendering on the small Windows Phone 7 screen. A lot of attention is given to sprite animation, since this seems to be the main focus of games for this platform. This book is not a geeky or gadget guide to the Windows Phone 7 platform. There are no hours devoted to the Windows Phone 7 hardware capabilities, and there is no overview of available applications in the marketplace.
This book is entirely focused on programming games with XNA Game Studio 4.0, targeting the Windows Phone 7 platform, and gets to the point quickly. This book does not try to cover every aspect of programming with XNA Game Studio 4.0. The goal of this book is to teach a relative beginner how to get graphics on the screen of a phone device, how to get user input via the touchscreen, and how to interact with the user. A lot of attention is given to user input, animation, and interaction. This requires a significant investment of time into graphical user interface (GUI) programming, which features prominently in these pages.
Our development tool of choice is obvious: Visual Studio 2010 Express for Windows Phone (with total emphasis on the C# language). This book does not spend much time covering Silverlight, although one small example of a Silverlight application is presented as a comparison to XNA. Nor is 3D rendering a high priority in this book. XNAs rendering capabilities are similar on all XNA platforms. Most of the same 3D rendering code will run on Windows, Xbox 360, and Windows Phone 7 without modification. The real difference is that custom shader effects are not supported on Windows Phone 7. The first hour will help you get up and running with the development environment.
Audience and Organization
This book assumes that the reader is new to the Windows Phone 7 platform, and new to XNA Game Studio 4.0. It assumes that the reader has a basic working knowledge of the C# language, but moves at a reasonable pace. This book does go deep into some advanced concepts, such as animation and collision response, but this is not a heavy rendering book. This is far more of a