class 3 july 14 2010 create new project
play

Class #3: July 14, 2010 Create New Project Open Visual C#: Start - PowerPoint PPT Presentation

Class #3: July 14, 2010 Create New Project Open Visual C#: Start Menu Microsoft XNA Game Studio 3.1 Visual C# Express Edition Create New Project: File New Project Type: XNA Game Studio 3.1 Template: Windows


  1. Class #3: July 14, 2010

  2. Create New Project  Open Visual C#:  Start Menu  Microsoft XNA Game Studio 3.1  Visual C# Express Edition  Create New Project:  File  New Project  Type: XNA Game Studio 3.1  Template: Windows Game 3.1

  3. Classes  Classes:  Program class in Program.cs  Game1 class in Game1.cs  Namespace AwesomeGame  Like a package in Java, is just a grouping for your classes.

  4. Program class  Has a main method that is called at runtime  Initializes a new Game1 object game.  Calls game.Run()  If you check Game1.cs you will not find this method, because it is in the Microsoft.XNA.Framework.Game class.  Game1 inherits from this class.  Run() begins the game loop.

  5. Game Loop running = true; while (running) { update(); draw(); }  As the programmer, it’s up to you to make sure everything gets updated in the update() function and displayed in the draw() function.

  6. Game1 class  Update()  Get player input  Move everything on screen  Check for collisions  Make decisions based on all the above. (is the player dead? Is the game over?)  Draw(), display objects to screen.

  7. Game1 class  GraphicsDeviceManager graphics;  Handles the management of the graphics device, or what is output to the screen. Defaults to a game window of 800x600.  SpriteBatch spriteBatch;  Allows us to draw our sprites to the screen.  Initialize()  Where we initialize our variables.  LoadContent()  Where we load our content – images, audio, models, etc.

  8. Other Data Types  Just like the Java API provides classes like String, the XNA framework is an API and we will be using many of its classes.  Today we will be using Vector2 and Texture2D

  9. Vector2  Vector2 is a container for 2 values,  an X coordinate and a Y coordinate, both floats. Useful for storing positions.  For example if we wanted to store the position of the background texture we would create a Vector2 : Vector2 backgroundPosition = new Vector2(0.0f, 0.0f);  To get or set the X coordinate, we do that like this: backgroundPosition.X = backgroundPosition.X +10; backgroundPosition = backgroundPosition +10;

  10. Texture2D class  Is a container for an image.  After you have added an image to your Content folder:  Declare under global variables: Texture2D backgroundTexture;  Load the texture under LoadContent(): backgroundTexture = Content.Load <Texture2D>(“Sprites \\ background”);

  11. Draw()  Have to use the following syntax to draw your texture in Draw(): spriteBatch.Begin(SpriteBlendMode.AlphaBlend); spriteBatch.Draw(texture, texturePosition,Color.White); spriteBatch.End();

  12. Yesterday’s Answers

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend