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 171
The Complete Example 166 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() {graphics = new...
Page 172
167 Welcome to XNA™ {myTexture = content.Load(“mytexture”); spriteBatch = new SpriteBatch(graphics.GraphicsDevice); } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent == true) {content.Unload(); } } //store some info about the sprite’s motion Vector2 spriteSpeed = new Vector2(50.0f, 50.0f); protected override void Update(GameTime gameTime) { // Allows the default game to exit on Xbox 360 and Windows if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==...
Page 173
168 Xbox 360™Han dbook {spriteSpeed.X *= -1; spritePosition.X = MaxX; } else if (spritePosition.X < MinX) { spriteSpeed.X *= -1; spritePosition.X = MinX; } if (spritePosition.Y > MaxY) { spriteSpeed.Y *= -1; spritePosition.Y = MaxY; } else if (spritePosition.Y < MinY) { spriteSpeed.Y *= -1; spritePosition.Y = MinY; } } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); //draw our sprite spriteBatch.Begin(SpriteBlendMode.AlphaBlend);...
Page 174
GOING BEYOND—3-D MODELS Introduction In the “Your First Game: Microsoft XNA Game Studio Express in 2-D” section, you saw a simple example that used the XNA Framework Content Pipeline to load a sprite (represented by a Texture2D object) and that used the XNA Framework APIs to draw it on the screen. This tutorial goes beyond that simple sample and introduces you to many concepts that XNA Game Studio Express makes easy, so you can focus on creating fun, interactive games.This first tutorial introduces you...
Page 175
Step 2: Create a New Project and Use the Spacewar Model Now that you have the art assets, let’s create the actual code project that you’ll be writing:> Click the File menu, then click New Project... to create a new project. > From the list of templates that appears, click either Windows Game or Xbox 360 Game, depending on whether you’re developing on the Xbox 360 or Windows. If you develop for Xbox 360, be sure you have a subscription to the XNA Creators Club; otherwise, you will not be able to play...
Page 176
Note that you don’t see the texture you added in the Solution Explorer. When you add a model, the textures that the model uses do not need to be added to the Content Pipeline. If you need to add textures that you will access manually (such as textures used for 2-D sprite drawing), do this via the Solution Explorer. Otherwise, you can simply copy the texture files to the appropriate folder. When the files are added to the project, the Content Pipeline automatically identifies them as content files and...
Page 177
Step 4: Display the Model Onscreen (and Make It Rotate) We’ll want to modify two of the methods in our Game1.cs file: > In the Draw method, we will draw the model on the screen with texture and lighting. > In the Update method, we will make the model change its orientation based on time, so it appears to rotate over time. Let’s do the harder work first: drawing the model. We have to use some XNA Framework methods to set up the model’s position and lighting to draw the model on the screen: > In the code,...
Page 178
This code uses helper methods provided by the XNA Framework to set up the necessary 3-D math and lighting to display the model on the screen. Use the World matrix to change the position of the model in the world, the View matrix to change the position and direction of the camera (your eye), and the Projection matrix to control how the view of the 3-D world is turned into a 2-D image (projected) on your screen. The call to CopyAbsoluteBoneTransformsTo and associated code inside the setup of the World...
Page 179
Ideas to Expand Got the urge to tinker with the project a bit? Try these ideas:> Modify the lighting parameters in the Draw call. Look at BasicEffect for an idea of what you can modify. > Instead of looking at a blue background, try adding an image as your background. (Hint: Make sure you use a call to SpriteBatch.Draw that allows you to specify a layerDepth parameter, and set that depth to 1.0f.) The Complete Example 174 Xbox 360™Han dbook #region Using Statements using System; using...
Page 180
175 Welcome to XNA™ } protected override void UnloadGraphicsContent(bool unloadAllContent) {if (unloadAllContent == true) {content.Unload(); } } protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)this.Exit(); modelRotation += (float)gameTime.ElapsedGameTime.TotalSeconds; base.Update(gameTime); } //Position of the model in world space, and rotation Vector3 modelPosition = Vector3.Zero; float modelRotation = 0.0f; //Position of...