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)

Scene manager


So now we have a basic scene graph. The only problem is switching between scenes. If we want to switch between the 2D and 3D scene, we need to change a lot of code in our game class. And that's only with two scenes; games tend to have a lot more. It would be a lot simpler to be able to add multiple scenes to our game and just select an active one. It's time we did just that.

The GameScene

If we want to create a scene manager, we first need a class that will represent a scene.

Properties

Let us start by identifying the properties of a scene. A scene should have a name, along with a list of 2D game objects and a list of 3D game objects.

public string SceneName { get; private set; }
public List<GameObject2D> SceneObjects2D { get; private set; }
public List<GameObject3D> SceneObjects3D { get; private set; }

Constructor

The constructor will have one argument of type string, being the name of the scene. In the body, we will set the name, and create new containers for our game...