XBOX 360 E User Guide
Have a look at the manual XBOX 360 E User Guide online for free. It’s possible to download the document as PDF or print. UserManuals.tech offer 11 XBOX manuals and user’s guides for free. Share the user manual or guide on Facebook, Twitter or Google+.
Step 3: Load the X ACT Project through the Content Pipeline You’ve just created and saved an XACT project that contains two wave files. The next step is to load this XACT project into the Content Pipeline:> Return to Visual C# 2005 Express Edition, and make sure your game project is loaded. If it isn’t, click Open Project on the File menu, and browse to your project. > Right-click on the Content\Audio folder in the Solution Explorer, select Add, and then select Existing Item. Using the dialog box that appears, browse to your game project’s (not Spacewar’s) Content\Audio folder, and then select MyGameAudio.xap. If you can’t see any files, make sure you change the Files of Type Selection field to read Content Pipeline Files. Click OK. The Content Pipeline automatically builds the .xap file as part of building your game. Now, all that’s left is to load the output files from your XACT project into your game. Let’s code! > View the code by double-clicking Game1.cs in Solution Explorer. > Find the Initialize method. Modify it to look like this: Notice that you need to load three files for your audio: > An AudioEngine by passing in the name of the XACT project file with an .xgs extension > A WaveBank by passing in your AudioEngine and the name of the wave bank you created in the XACT project with an .xwb extension > A SoundBank by passing in your AudioEngine and the name of the sound bank you created in the XACT project with an .xsb extension Once you have done this, you’re ready to add the code to play your sounds when game events happen! 186 Xbox 360™Han dbook AudioEngine audioEngine; WaveBank waveBank; SoundBank soundBank; protected override void Initialize() { audioEngine = new AudioEngine(“Content\\Audio\\MyGameAudio.xgs”); waveBank = new WaveBank(audioEngine, “Content\\Audio\\Wave Bank.xwb”); soundBank = new SoundBank(audioEngine, “Content\\Audio\\Sound Bank.xsb”); base.Initialize(); } C# Code Protected by copyright. Unauthorized or unlawful copying or downloading \ expressly prohibited.
Step 4: Play Sounds Using the Audio API Access the sounds you wish to play in your game via a Cue object, which you can get by calling GetCue or play directly by calling PlayCue.In this tutorial, we do both. For our looping engine sound, we call GetCue to get and hold the engine cue, and pause and resume the cue as our engines turn on and off when the user pulls the trigger. When the player presses 1to warp, we play the hyperspace sound by calling PlayCue. Find the UpdateInput method. Modify it to look like this: 187 Welcome to XNA™ //Cue so we can hang on to the sound of the engine Cue engineSound = null; protected void UpdateInput() { //get the gamepad state GamePadState currentState = GamePad.GetState(PlayerIndex.One); 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 held down modelVelocityAdd *= currentState.Triggers.Right; //finally, add this vector to our velocity modelVelocity += modelVelocityAdd; GamePad.SetVibration(PlayerIndex.One, currentState.Triggers.Right,currentState.Triggers.Right); //set some audio based on whether we’re pulling trigger if (currentState.Triggers.Right > 0) { if (engineSound == null) {engineSound = soundBank.GetCue(“engine_2”); engineSound.Play(); C# Code Protected by copyright. Unauthorized or unlawful copying or downloading \ expressly prohibited.
Many things are happening here. Here’s a breakdown of what we’re doing: //Cue so we can hang on to the sound of the engine Cue engineSound = null; The Cue represents an instance of a sound. In this case, this Cue represents the sound of our engines when we pull the right trigger. 188 Xbox 360™Han dbook } else if (engineSound.IsPaused) { engineSound.Resume(); } } else { if (engineSound != null && engineSound.IsPlaying) {engineSound.Pause(); } } //in case you get lost, press Ato warp back to the center if (currentState.Buttons.A == ButtonState.Pressed) { modelPosition = Vector3.Zero; modelVelocity = Vector3.Zero; modelRotation = 0.0f; //make a sound when we warp soundBank.PlayCue(“hyperspace_activate”); } } } C# Code Protected by copyright. Unauthorized or unlawful copying or downloading \ expressly prohibited.
This code manages the engine sound. Since we enter this code once every frame, we have to make sure we don’t continually try to play the same sound—we only want to modify the state of the Cue if there’s a change, such as the trigger being released. This code uses GetCue the first time through the loop to ready the Cue to play and to play it if the trigger is down. From that point forward, each release of the trigger calls Pause and halts playback of the Cue. Subsequently pulling the trigger again will calls Resume, and playback continues. In case you get lost, press 1to warp back to the center Finally, when the user presses 1to warp, get and play a sound all at once using PlayCue. Since we don’t need to stop or pause this sound, but can just let it play, there’s no reason to hold on to the sound in a Cue object. 189 Welcome to XNA™ //set some audio based on whether we’re pulling trigger if (currentState.Triggers.Right > 0) { if (engineSound == null) {engineSound = soundBank.GetCue(“engine_2”); engineSound.Play(); } else if (engineSound.IsPaused) { engineSound.Resume(); } } else { if (engineSound != null && engineSound.IsPlaying) {engineSound.Pause(); } } C# Code if (currentState.Buttons.A == ButtonState.Pressed) { modelPosition = Vector3.Zero; modelVelocity = Vector3.Zero; modelRotation = 0.0f; //make a sound when we warp soundBank.PlayCue(“hyperspace_activate”); } C# Code Protected by copyright. Unauthorized or unlawful copying or downloading \ expressly prohibited.
Congratulations! At this point, you have a spaceship that floats in 3-D space, that moves around when you use your Xbox 360 Controller, and that makes sounds and gives you feedback in your controller. You have created the very beginnings of a 3-D game using XNA Game Studio Express, and you’re just getting started. There’s so much more to explore! Ideas to Expand If you’re ready to go further with this sample, try a few of these ideas:> Use some of the advanced runtime parameter control functionality of XACT to change the volume and pitch of your engines as you change pressure on your right trigger. > Add some background music and try setting volumes using categories. By this point, you have many of the basic elements you need to build a game: graphics, input, and sound. Even so, you may be wondering, “How do I build a game?” Games are an expressive process, with plenty of room for creative problem-solving. There is truly no “right way” to make a game. With the example we have created, there are still many missing elements. What does the ship interact with? Does it have a goal? What obstacles prevent the ship from reaching the goal? Answering these questions will define your game and make it your own. Play some games that inspire you, check out the XNA Team Blog, read up on XNA in the Programming Guide, explore the XNA Framework, and have fun building a game of your own. We hope you enjoy XNA Game Studio Express! The Complete Example 190 Xbox 360™Han dbook #region Using Statements using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; #endregion public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; ContentManager content; public Game1() C# Code Protected by copyright. Unauthorized or unlawful copying or downloading \ expressly prohibited.
191 Welcome to XNA™ {graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); } AudioEngine audioEngine; WaveBank waveBank; SoundBank soundBank; protected override void Initialize() { audioEngine = new AudioEngine(“Content\\Audio\\MyGameAudio.xgs”); waveBank = new WaveBank(audioEngine, “Content\\Audio\\Wave Bank.xwb”); soundBank = new SoundBank(audioEngine, “Content\\Audio\\Sound Bank.xsb”); base.Initialize(); } //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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) C# Code Protected by copyright. Unauthorized or unlawful copying or downloading \ expressly prohibited.
192 Xbox 360™Han dbook this.Exit(); //Get some input UpdateInput(); //update audioEngine audioEngine.Update(); //add velocity to current position modelPosition += modelVelocity; //bleed off velocity over time modelVelocity *= 0.95f; base.Update(gameTime); } //Cue so we can hang on to the sound of the engine Cue engineSound = null; protected void UpdateInput() { //get the gamepad state GamePadState currentState = GamePad.GetState(PlayerIndex.One); 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 held down modelVelocityAdd *= currentState.Triggers.Right; //finally, add this vector to our velocity modelVelocity += modelVelocityAdd; GamePad.SetVibration(PlayerIndex.One, currentState.Triggers.Right,currentState.Triggers.Right); C# Code Protected by copyright. Unauthorized or unlawful copying or downloading \ expressly prohibited.
193 Welcome to XNA™ //set some audio based on whether we’re pulling trigger if (currentState.Triggers.Right > 0) {if (engineSound == null) {engineSound = soundBank.GetCue(“engine_2”); engineSound.Play(); } else if (engineSound.IsPaused) { engineSound.Resume(); } } else { if (engineSound != null && engineSound.IsPlaying) {engineSound.Pause(); } } //in case you get lost, press Ato warp back to the center if (currentState.Buttons.A == ButtonState.Pressed) { modelPosition = Vector3.Zero; modelVelocity = Vector3.Zero; modelRotation = 0.0f; //make a sound when we warp soundBank.PlayCue(“hyperspace_activate”); } } } //Position of the model in world space, and rotation Vector3 modelPosition = Vector3.Zero; float modelRotation = 0.0f; //Position of the camera in world space, for our view matrix Vector3 cameraPosition = new Vector3(0.0f, 50.0f, -5000.0f); //Aspect ratio to use for the projection matrix C# Code Protected by copyright. Unauthorized or unlawful copying or downloading \ expressly prohibited.
194 Xbox 360™Han dbook float aspectRatio = 640.0f / 480.0f; protected override void Draw(GameTime gameTime) {graphics.GraphicsDevice.Clear(Color.CornflowerBlue); //Copy any parent transforms Matrix[] transforms = new Matrix[myModel.Bones.Count]; myModel.CopyAbsoluteBoneTransformsTo(transforms); //Draw the model; a model can have multiple meshes, so loop foreach (ModelMesh mesh in myModel.Meshes) {//This is where the mesh orientation is set, as well as our camera and projection foreach (BasicEffect effect in mesh.Effects) {effect.EnableDefaultLighting(); effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation)* Matrix.CreateTranslation(modelPosition); effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up); effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f); } //Draw the mesh; will use the effects set above. mesh.Draw(); } base.Draw(gameTime); } } C# Code Protected by copyright. Unauthorized or unlawful copying or downloading \ expressly prohibited.
Xbox 360™Han dbookThe Official User ’s Guide 12 : What Is Old Is New Again Protected by copyright. Unauthorized or unlawful copying or downloading expressly prohibited.