Home > XBOX > Video Game Console > XBOX 360 E User Guide

XBOX 360 E User Guide

Here you can view all the pages of manual XBOX 360 E User Guide. The XBOX manuals for Video Game Console are available online for free. You can easily download all the documents as PDF.

Page 181

GOING BEYOND—MAKING YOUR
MODEL MOVE USING INPUT
Step 1: Connect Your Xbox 360™Controller
The first step in this tutorial is making sure you can provide some input to your game. We’ll be using the Xbox
360 Controller throughout this tutorial. Designed for use with both a Windows computer and an Xbox 360, the
controller features many analog and digital inputs, as well as vibration motors to give the user feedback.There are other ways to take input—the XNA Framework has support for keyboard and mouse...

Page 182

The code you’ve just added to input runs every frame and does a few different things. First, it gets rid of the
code that automatically rotates the ship; you’ll be controlling that with your controller. Next, it calls a method
named UpdateInput, which you’ll have to create in the next step. Last, it adds our model’s velocity to its position,
moving it in the world by its velocity, and decays the velocity so that eventually the model slows down. 
Step 3: Take Input from the User
Now that the model is set...

Page 183

> Find some empty space in your code below the Update method. 
> Add a new method called protected void UpdateInput(). Modify the method to look like this:
That method does a lot. Let’s take it piece by piece to investigate exactly what you’re doing with input
and the model:
//get the gamepad state
GamePadState currentState = GamePad.GetState(PlayerIndex.One);
178
Xbox 360™Han dbook

protected void UpdateInput()
{ //get the gamepad state
GamePadState currentState = GamePad.GetState(PlayerIndex.One);
if...

Page 184

This call to GetState retrieves a GamePadState object, which contains the information we need about the 
controller—in this case, stick and trigger positions.
//rotate the model using the left stick; scale it down
modelRotation -= currentState.ThumbSticks.Left.X * 0.10f;
Retrieving the  X-axis value of the left stick (left and right movement) returns a value that is added to the
modelRotation variable. The value is scaled down so that the rotation isn’t too fast. 
//create some velocity if the right...

Page 185

Congratulations!
At this point, your ship moves and gives you feedback through your Xbox 360 Controller. The player is in control
of the action.When you’re ready, let’s add the final element—audio—to get you on your way. Once you can control the
action and can see and hear the results of your actions, you’re well on your way to creating a game.
Ideas to Expand
Want to play around some more with input? Try these ideas:
> Change the game to view your model from the top, as in a top-down arcade game....

Page 186

181
Welcome to XNA™

}
//3d model to draw
Model myModel;
protected override void LoadGraphicsContent(bool loadAllContent)
{if (loadAllContent)
{myModel = content.Load(“Content\\Models\\p1_wedge”);
}
}
protected override void UnloadGraphicsContent(bool unloadAllContent)
{ if (unloadAllContent == true)
{content.Unload();
}
}
//Velocity of the model, applied each frame to the model’s position
Vector3 modelVelocity = Vector3.Zero;
protected override void Update(GameTime gameTime)
{ if...

Page 187

182
Xbox 360™Han dbook

if (currentState.IsConnected)
{//rotate the model using the left stick; scale it down
modelRotation -= currentState.ThumbSticks.Left.X * 0.10f;
//create some velocity if the right trigger is down
Vector3 modelVelocityAdd = Vector3.Zero;
//find out what direction we should be thrusting, using rotation
modelVelocityAdd.X = -(float)Math.Sin(modelRotation);
modelVelocityAdd.Z = -(float)Math.Cos(modelRotation);
//now scale our direction by how hard the trigger is down
modelVelocityAdd...

Page 188

GOING BEYOND—AUDIO
Step 1: Get Some Wave Files
Audio in XNA Game Studio Express is created using the Microsoft Cross-Platform Audio Creation Tool (XACT). Wave
files (.wav) are assembled into an XACT project and built into wave banks that are loaded into your game.The first thing to do is get some wave files. This is where the Spacewar project you created in “Going
Beyond—3-D Models” comes in handy. Let’s go get the wave files from that project:
> Make sure your project from “Going Beyond—Making Your...

Page 189

Step 2: Create an X ACT™Project with Wave Files
If you’ve noticed that you don’t add wave files like other content files (i.e., via the Solution Explorer), you’re
right—the Content Pipeline processes XACT projects, which are compilations of wave files and not just the
raw wave files themselves. We must now create that compilation using the Microsoft Cross-Platform Audio
Creation Tool (XACT).Let’s launch XACT:
> From your Start menu, browse to All Programs, then Microsoft XNA Game Studio Express, and...

Page 190

> Add both of your wave files to the wave bankwindow. Click on the wave bank window to make
sure it is active, then right-click Wave Banks, and
then click Insert Wave File(s). Browse to your
game project folder, and into the Content\Audio\
Waves folder. Select both wave files. If you suc-
cessfully added them, they appear in the wave
bank window, which looks  similar to the screen
directly to the right: 
> For each wave listed in the wave bank window, drag the wave from the wave bank window to the
sound...
Start reading XBOX 360 E User Guide

Related Manuals for XBOX 360 E User Guide

All XBOX manuals