Creating a Test Demo for the Xbox 360

We are going to create a simple application we can deploy and then debug on the Xbox 360. To get started we need to create another project, but this time we will use the Xbox 360 Game template to start with. To deploy a game to the Xbox 360, the template created a file called AssemblyInfo.cs. The Windows Game template also creates this file but it holds a little more importance for Xbox 360 games. Once we open this file we can see an attribute called AssemblyTitle. This attribute determines...

Creating a Sound Demo

Now we need to add in another Windows game project to our XELibrary solution. We can call this new project SoundDemo. We can also set up our solution for our Xbox 360 project if we want to test it on the console. Now we need to make sure our game is referencing the XELibrary project. Once we have our XELibrary referenced correctly, we can start writing code to test out our new sound class (and updated input class). We need to use the library's namespace at the top of our game class as follows...

Plugging in Our Sound Manager

Finally we can get to our sound manager code. We discussed XACT and how we can use it to create sound projects that our games can consume. We also extended our input handler code and now we are ready to dive into the code that will allow us to play the sounds we set up in our XACT project. To begin, we need to create a new game component code file inside of our XELibrary called SoundManager.cs. The code for this class can be found in Listing 7.2. LISTING 7.2 SoundManager.cs using System using...

Setting Up the Game Skeleton

To get started, we need to create our solution and project files and add the XELibrary project as well. We can call this game SimpleGame as it will be a rather basic but complete game. After we have our environment set up, we can jump right into our Game1.cs code. To begin with, as usual, we create some member fields we know we will need public enum GameState StartMenu, Scene public GameState State GameState.StartMenu . Setting Up the Game Skeleton . Creating Parallax Scrolling . Switching...

Creating the Tunnel Vision Game

The tunnel to our space station is being attacked, so we need to defend our tunnel and not let the enemies breach the opening. We have missiles that we can fire. Fortunately, the enemy does not have any. They simply attack in swarms, which mean we need to take swift action to destroy them. To get started, we need to make a copy of our GameStateDemo from Chapter 15, Finite State Machines and Game State Management. We want to use the latest XELibrary from the last...

Creating the Game Logic

After we successfully compile and run our game, we can start working on our game logic. Fortunately, we have the framework in place where we can easily put in our game code. We will first work on our game play by modifying the playing state code file. We need to remove the font from our private member fields and add in the following fields private MissileManager missileManager private EnemyManager enemyManager private List< Level> Levels private int currentLevel private float...

Loading 3D Models

The XNA Framework's Content Pipeline handles loading .X and .FBX files automatically when they are pasted into the Solution Explorer (or included in the project). This is when the Content Pipeline goes through the process described in the previous section of importing, processing, and compiling the data. We then can use our game class and the Content Manager to read the model information. We will start by creating a new project, which we can call Load3DObject. We can create both the Windows and...

Measure Measure Measure

The title of this section really says it all. In real estate they say what matters is location, location, location. In the performance realm, measuring is what really matters. How else can we know if we are meeting our goals if we do not first take the time to measure along the way Before we start writing code we need to take a benchmark measurement. Then we can see as we add functionality whether or not we are adversely affecting our performance goals. So what is our goal At the very least our...

Understanding Variations

To accomplish something more than just playing sounds we need to understand variations. With variations we can assign many waves to a track and we can create different events for those tracks to create a sound. We can assign many sounds to a cue. We can then set up how those sounds or waves are to be played. We will be utilizing XACT to create different variations and then we are going to write a library component that a demo can use to play these cues. We can close out our existing XACT...

Updating Our Input Handler

Before we actually dig into the code to utilize the XACT project we just created, let's back up a minute and take another look at our input handler. In particular we want to extend our keyboard and gamepad functionality. Currently, if we try to trigger any event with a key press or a button push we will get the event kicked off several times. This is because for every frame we are checking in our Update method, if a key is pressed for a fraction of a second the method will return true for many...

Fade to Color

We are going to create another simple demo. In fact, we can continue to modify the code we have open. This demo will wait one second after the program launches and then start to do a fade to black, although we could fade to any color we want. First, we want to add the following member fields to our code private float fadeAmount private Texture2D fadeTexture Next, in our LoadGraphicsContent method we want to create a texture that we can store in our fadeTexture variable. We can do this with the...

Creating a Skybox

We are going to create a project that will contain the content, content processor, and content compiler. After creating this project we will create another file inside of our XELibrary to read the skybox data. Finally, we will create a demo that will utilize the XELibrary's Skybox Content Reader, which the Content Manager uses to consume the skybox. Before we actually create the project we should first examine a skybox and its purpose in games. A skybox...

Keeping Track of High Scores

After playing the game and seeing the score, the next logical step is to create a way to store our high score list. Currently, the XNA Framework does not expose the gamer tag's profile name. It also does not expose the built-in display keyboard. To keep the code simple, we are going to hard-code the name Playerl when a high score is reached. There are a couple of community projects where developers have created keyboard game components. If desired, they could be plugged into the code to allow...

XNA Game Components

Now that we have created this very exciting square, let's take a look at what it did to our performance. In this section we are going to create an XNA GameComponent. A game component allows us to separate pieces of logic into their own file that will be called automatically by the XNA Framework. We will take the frame rate code we added in our PerformanceBenchmark project from the last chapter and create a game component out of it. To do this, we need to add another file to our project, which...

Checking Performance

Now that we have our fps functionality inside of a game component we can check out if the code we wrote for the demo to display the rectangle is performing well or not. Fortunately, we recorded the frame rate we were getting in the last chapter so we have a baseline from which to work. We will need to set up an Xbox 360 game project for this solution as we discussed in Chapter 2, XNA and the Xbox 360. Once we have it set up, we can run our application on our machine and on the Xbox 360 to...

Understanding the Garbage Collector

A big plus of writing managed code is the fact that we do not need to worry about memory leaks from the sense of losing pointers to referenced memory. We still have memory leaks in managed code, but whenever the term is used it is referring to not decommissioning variables in a timely fashion. We would have a memory leak if we kept a handle on a pointer that we should have set to null. It would remain in memory until the game exits. We should use the using statement. An example of the using...

Installing the DirectX Runtime

We also need the DirectX 9 runtime if it isn't already on the machine. To get started, follow these steps 1. Run the dxwebsetup.exe file from Microsoft's website. This can be found by clicking on the DirectX Runtime Web Installer link at the bottom of the Creator's Club Resources Essentials web page This file contains the redistribution package of the February 2007 DirectX 9. You will need to be connected to the Internet so it can completely install the application. 2. We are greeted with the...

Table of Contents

Part I Get Up and Running with XNA on Your PC and Xbox 360 1 Introducing XNA and XNA Game Studio Express 7 What Is the XNA The Foundation of the XNA XNA Installing Visual C Installing the DirectX Installing XNA Game Studio Creating Spacewar Windows Compiling and Running Creating Spacewar Xbox 360 Buying the XNA Creators Club Connecting the Xbox 360 to the Deploying on the Xbox Debugging on the Xbox Creating a Test Demo for the Xbox Programming for Dual The .NET Compact Framework on the Xbox 3...

Hardware and Software Requirements

The code in this book is compiled against the XNA Framework 1.0 Refresh. In order to complete the games and demos in this book the requirements that follow must be met. The following operating systems are supported Windows XP requires Service Pack 2 or later. When running XNA Framework games on Windows, a graphics card that supports Shader Model 1.1 is required. This book has samples that use Shader Model 2.0 and a couple that use Shader Model 3.0. To get the most from this book, a graphics...