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)

Drawing models


There are several steps we need to take when drawing 3D models. Start by downloading the start files and open the MainGame class. Once this is done, we need to declare our View and Projection matrices. As these contain our camera settings, they will be the same for all 3D models. For each model, we'll need to add fields, load the model, and then draw it.

Adding fields

We'll create three fields: a field for the hero of type Model, and fields for the View and Projection matrices of type Matrix.

Model _hero;
Matrix _view, _projection;

Initialize

In the Initialize method, we will set the values for our View and Projection matrices.

  1. We can create the View matrix by using the static Matrix.CreateLookAt method. It has three arguments. The first is the position of the camera, the second what it's looking at, and the third the up vector. We will place the camera 20 units along the positive z axis, pointed back at the origin.

  2. For the Projection matrix we will use an orthographic projection...