Table Of Contentwww.it-ebooks.info
Building your First Mobile
Game using XNA 4.0
A fast-paced, hands-on guide to building a 3D game
for the Windows Phone 7 platform using XNA 4.0
Brecht Kets
Thomas Goussaert
BIRMINGHAM - MUMBAI
www.it-ebooks.info
Building your First Mobile Game using XNA 4.0
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 authors, 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: December 2012
Production Reference: 1191212
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84968-774-4
www.packtpub.com
Cover Image by Lino Drieghe (contact@linodriegheart.com)
www.it-ebooks.info
Credits
Authors Project Coordinator
Brecht Kets Michelle Quadros
Thomas Goussaert
Proofreader
Mario Cecere
Reviewers
Kurt Jaegers
Indexer
Justin Witol
Hemangini Bari
Cătălin Zima-Zegreanu
Graphics
Acquisition Editor
Aditi Gajjar
Dilip Venkatesh
Production Coordinator
Commissioning Editor
Melwyn D'sa
Meeta Rajani
Cover Work
Technical Editors
Melwyn D'sa
Kaustubh S. Mayekar
Kirti Pujari
www.it-ebooks.info
About the Authors
Brecht Kets is a Senior Lecturer at Howest University in Belgium, where he teaches
game development in one of the leading international game development study
programs, Digital Arts and Entertainment (www.digitalartsandentertainment.
com). He's been actively involved in game development for several years, and has
been writing about XNA since the launch in December 2006. He hosts the website
www.3dgameprogramming.net and has received the Microsoft Most Valuable
Professional award in the category DirectX/XNA five times in a row for his
contributions in the community.
Brecht has also co-authored the video series XNA 3D Game Development By Example,
Packt Publishing.
Thomas Goussaert graduated in Digital Arts And Entertainment (DAE), from
Howest University. With a wide range of skills acquired by his studies, he explored
the world of programming and game development. Thomas is always curious
and eager to learn new things; always feeding his passion for programming. Now
he's a lecturer at Howest University, where he teaches game development in one
of the leading international game development study programs, Digital Arts and
Entertainment (www.digitalartsandentertainment.com). It's nice to have a
passion for programming, but it's even better to share it with the world!
Thomas has also co-authored the video series XNA 3D Game Development By
Example, Packt Publishing
www.it-ebooks.info
Acknowledgement
First of all, we would like to thank our family and friends for supporting us while
writing this book, without which this series would not have been possible. We would
also like to thank everyone at Packt Publishing for giving us this opportunity, along
with the reviewers who did an excellent job at making this book what it is.
Finally we would like to thank Mike Ptacek for providing us with the artwork
for this series, making coder-art needless and sparing your eyes from permanent
damage. We would also like to thank Lino Drieghe for making the cover image of
this book.
www.it-ebooks.info
About the Reviewers
Kurt Jaegers is an Oracle Database Administrator and Windows network
Admin, as well as a long-time hobbyist game developer. He has built games
for everything from the Commodore 64 to the Xbox 360. He is the owner of
http://www.xnaresources.com, and the author of XNA Game Development
by Example, Packt Publishing for both C# and Visual Basic, and XNA 4 3D Game
Development by Example, Packt Publishing.
Justin Witol grew up programming and he loved it ever since he was young when
his mother first introduced him to Basic. For the past few years he has been working
on game programming and has been developing an open source game engine for
practice. He helps out within the community mainly dealing with C# and XNA,
but at times he helps out in other fields as well, so when asked about reviewing this
book he immediately responded with a yes. He hopes the book has helped to further
your understanding of not only game development but programming in general. If
you ever have any questions or just need some help with something dealing with
programming feel free to stop by his website at www.WitolProductions.com and
just ask.
Cătălin Zima-Zegreanu is very passionate about game design and development.
He has been working with games and graphics technologies for more than the last
seven years. He has been awarded the title of Microsoft MVP for DirectX/XNA for
five years, in recognition of his expertise and dedication to the technology. At the
moment, he is designing and developing mobile games with an awesome team, and
enjoying life with awesome family and friends.
www.it-ebooks.info
www.PacktPub.com
Support files, eBooks, discount offers
and more
You might want to visit www.PacktPub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files
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?
• Fully searchable across every book published by Packt
• Copy and paste, print and bookmark content
• 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.
Instant Updates on New Packt Books
Get notified! Find out when new books are published by following @PacktEnterprise on
Twitter, or the Packt Enterprise Facebook page.
www.it-ebooks.info
www.it-ebooks.info
Table of Contents
Preface 1
Chapter 1: Getting Started 7
Developing for Windows Phone 7
Installing the Windows Phone SDK 8
Registering your Windows Phone 9
Getting started with your first application 10
The Game class 13
Fields 14
Constructor 14
Initialize 14
LoadContent 14
UnloadContent 15
Update 15
Draw 16
Summary 16
Chapter 2: 2D Graphics 17
2D coordinate system 17
Adding content 18
Drawing sprites 20
Adding fields 20
Loading textures 20
Drawing textures 20
Refactoring our code 21
Render context 22
The base class 23
Properties 23
Constructor 24
Methods 24
www.it-ebooks.info