Getting Started XNA Game Studio 4.0 To download

Getting Started XNA Game Studio 4.0 To download

Getting Started XNA Game Studio 4.0 To download XNA Game Studio 4.0 itself, go to http://www.microsoft.com/download/en/details.aspx?id=23714 XNA Game Studio 4.0 needs the Microsoft Visual Studio 2010 development environment, XNA Game Studio 4.0 works with any of the following Microsoft Visual Studio 2010 products. Microsoft Visual Studio 2010 Express for Windows Phone Microsoft Visual C# 2010 Express Edition Microsoft Visual Studio 2010 Standard Edition Microsoft Visual Studio 2010 Professional Edition XNA Game Studio requires the Microsoft .NET Framework 4.0. The setup program for Microsoft Windows Phone Developer Tools installs the .NET Framework if it is not installed already on your computer. You also can install the .NET Framework from the Microsoft .NET Framework Developer Center. High Dynamic Range (HDR) Rendering vs Reach If you see this message when attempting to build an XNA game it probably means that your graphics card does not support High Dynamic Range (HDR) rendering.

You will need to change the properties/settings of your project by right-clicking the game project name and changing the Game Profile... Additional Required Software Installed by Setup The XNA Game Studio setup program also installs the following required software: XNA Game Studio setup installs the DirectX runtime, which is required to use the XNA Framework Game API. XNA Game Studio Setup installs multiple versions of the Microsoft Cross-platform Audio Creation Tool (XACT). XNA Game Studio Setup installs Microsoft Games for Windows LIVE Redistributable, version 2.0.687.0. This software provides support for various gamer services such as retrieving player preferences for local accounts, as well as programmatically displaying various LIVE Guide user interface screens. Creating your First XNA Program Step 1: Select New Project, choose Visual C# from the Installed Templates list on the left and specify Windows Game (4.0). Give your project an appropriate name, such as FaceBall and then click OK.

Step 2: Test Run your program. You should see a new Windows Form appear with a light blue background (CornFlowerBlue). You should note that this window is not resizable. Before moving on, let's take a look at the automatically generated game code... namespace FaceBall { public class faceBall : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; public faceBall() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { base.Initialize();

} protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); } your game class inherits from the Microsoft.Xna.Framework.Game class Creates a new GraphicsDeviceManager and registers it to handle the configuration and management of the graphics device for the specified Game. Enables a group of sprites to be drawn using the same settings. Add your initialization logic here This method is called once at start of game and is where you should load your content. This is where you will update the state of your game . Update( ) is called once for each pass through the game loop.

protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); This is where you generate the display for base.Update(gameTime); the current frame. Draw( ) is called once for } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); base.Draw(gameTime); } } } each pass through the game loop.

Step 3: Now you will associate "content" (such as sprite bitmaps) with your game project. Image, sound and other resources can be found in Resources (see Home Page). Download face.bmp and background.bmp and put them somewhere easy to find them such as on your desktop. Right-click FaceBallContent in Solution Explorer, choose Add Existing Item and then navigate to one of the bitmaps being added to content. Repeat for the other bitmap. Step 4: FaceBall is a simple demo that bounces a smiley face around in the graphics display region of the game. The following code is inserted at the top of the class. Texture2D faceTexture; Texture2D backgroundTexture; Vector2 facePosition; public int maxX, minX, maxY, minY; public int faceVx = 5;

public int faceVy = 2; Step 5: Add code to the Initialize( ) method to set the min and max limits of graphics viewport. Viewport view = graphics.GraphicsDevice.Viewport; base.Initialize(); maxX = view.Width; minX = 0; maxY = view.Height; minY = 0; facePosition.X = view.Width / 2; facePosition.Y = view.Height / 2; Step 6: Add code to the LoadContent( ) method to load the face and background bitmaps. faceTexture = Content.Load("face"); backgroundTexture = Content.Load("background");

Step 7: Add code to the Update( ) method to keep the bouncing face inside the graphics viewport. facePosition.X += faceVx; if (facePosition.X > maxX - faceTexture.Width) faceVx *= -1; if (facePosition.X < minX) faceVx *= -1; facePosition.Y += faceVy; if (facePosition.Y > maxY - faceTexture.Height) faceVy *= -1; if (facePosition.Y < minY) faceVy *= -1; Step 8: Add code to the Draw( ) method to draw the background and the face in the current position. spriteBatch.Begin(); spriteBatch.Draw(backgroundTexture, new Rectangle(minX,minY,maxX,maxY),Color.White); spriteBatch.Draw(faceTexture, facePosition, Color.White); spriteBatch.End();

Note that the default transparency color in XNA is magenta (255,0,255). The background image is automatically stretched to fit size of the rectangle specified. FaceBall Code Summary namespace FaceBall { public class faceBall : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D faceTexture; Texture2D backgroundTexture; Vector2 facePosition;

public int maxX, minX, maxY, minY; public int faceVx = 5; public int faceVy = 2; public faceBall() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } Viewport view = graphics.GraphicsDevice.Viewport; maxX minX maxY minY protected override void Initialize() {

base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); } = = = = view.Width; 0; view.Height; 0; facePosition.X = view.Width / 2; facePosition.Y = view.Height /

2; faceTexture = Content.Load("face"); protected override void Update(GameTime gameTime)backgroundTexture = Content.Load("background"); { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) facePosition.X += faceVx; this.Exit(); if (facePosition.X > maxX base.Update(gameTime); faceTexture.Width) } faceVx *= -1; if (facePosition.X < minX) faceVx *= -1; facePosition.Y += faceVy; if (facePosition.Y > maxY faceTexture.Height)

faceVy *= -1; if (facePosition.Y < minY) faceVy *= -1; spriteBatch.Begin(); spriteBatch.Draw(backgroundTexture, new Rectangle(minX, minY, maxX, maxY), Color.White); spriteBatch.Draw(faceTexture, facePosition, Color.White); spriteBatch.End(); protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); base.Draw(gameTime); } } } Step 9: Run the program to verify correct operation.

Recently Viewed Presentations

  • Using Strong Verbs

    Using Strong Verbs

    Brainstorm a mini-list of strong verbs that might be more effective. Choose the verb that best expresses your ideas and creates a powerful mental image Brainstorm Box went: goes: told Use a Thesaurus to help you find more exciting verbs....
  • Communication Systems : Prof. Ravi Warrier AMPLITUDE MODULATION

    Communication Systems : Prof. Ravi Warrier AMPLITUDE MODULATION

    To produce SSB signal from DSB signal ideal filters should be used to split the spectrum in the middle so that the bandwidth of bandpass signal is reduced by one half. In VSB system one sideband and a vestige of...
  • The Cask of Amontillado By Edgar Allan Poe

    The Cask of Amontillado By Edgar Allan Poe

    Edgar Allan Poe. Poe was born January 19, 1809 in Boston, Massachusetts. His parents were actors and died before he was 3. He was raised by John and Frances Allan in Richmond, Virginia
  • Title of Subject : Motorman/Tram Diesel Last Reviewed

    Title of Subject : Motorman/Tram Diesel Last Reviewed

    Examine the roof and ribs for loose materials and the walkways for potential slipping/tripping hazards. Scale loose roof and ribs as necessary. Remove potential slipping/tripping hazards. Preoperational Checks: PA State Law - Diesel operators must have received initial 8 hours...
  • Grant Management System - Mississippi Department of ...

    Grant Management System - Mississippi Department of ...

    System will score the ratings of all committee members. Staff currently entering series of ratings in an excel spreadsheet. Eliminate input errors. System will free up staff time. More timely completion of scoring
  • PHILOSOPHY OF DREAMS AND SLEEPING - Matskut

    PHILOSOPHY OF DREAMS AND SLEEPING - Matskut

    John Suttonlaments in hisarticle "Dreaming" thatalthoughthere is somerecentdevelopment in the philosophy of dreaming, the discipline is in a veryprimitivestatecompared to, for example, philosophy of emotions, memory, colour vision etc. However, there is now The International Association for the Study of...
  • Recovery-oriented Services for People Experiencing Homelessness

    Recovery-oriented Services for People Experiencing Homelessness

    Recovery-oriented Services for People Experiencing Homelessness. Who We Are. Cheryl Gagne, Sc.D. t3/Center for Social Innovation. Alex Jeffrey. What comes to mind when you hear the term "recovery"? Recovery. Recovery is described as a deeply personal,
  • Production Planning and Control Materials Requirement Planning Dr.

    Production Planning and Control Materials Requirement Planning Dr.

    BOM Explosion: gross requirements for components Production Planning and Control- Materials Requirement Planning (*) Inputs Master Production Schedule (MPS): due dates and quantities for all top level items Bills of Material (BOM): for all parent items Inventory Status: (on hand...