lecture 4 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Lecture 4 PowerPoint Presentation
Download Presentation
Lecture 4

Loading in 2 Seconds...

play fullscreen
1 / 11

Lecture 4 - PowerPoint PPT Presentation

97 Views
Download Presentation
Lecture 4
An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Lecture 4 XNA Review Richard Gesick

  2. TheMajor Methods of an XNA Game Constructor - initialize and set up variables as usual LoadContent - load SpriteFont, Texture2D, etc. Update - handle all user input and update game state Draw - handle drawing the images/graphics to the screen

  3. NO drawing should happen in Update and No input/state changes should happen in Draw

  4. Content Draw your assets (using transparent backgrounds if desired) in your favorite paint program.  GIMP and Paint.NET are both free Add your assets to the Content folder and then add them to your project (via "Project | Add | Add Existing...")

  5. Create attributes within the class to hold the assets Texture2D bowl; then Load the assets into the attributes in the LoadContent method bowl = Content.Load<Texture2D>("bowl");

  6. User Input Handle user input (via the GetState method of the Keyboard class) currentKeyboardState= Keyboard.GetState(PlayerIndex.One); if (currentKeyboardState.IsKeyDown(Keys.Left)) { bowl_position.X -= 3; if (bowl_position.X < 0) bowl_position.X = 0; } . . .

  7. Draw(1) Draw icons/sprites to the screen (via the Draw method of the SpriteBatch class) GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(bowl,bowl_position, Color.White);

  8. Draw (2) Draw strings to the screen (via the DrawString method of the SpriteBatch class) spriteBatch.DrawString(stats_font, "Food consumed: " + FoodCaught, pos, Color.White); Be sure to place all screen manipulation inside the Begin/End methods of the SpriteBatch class

  9. Random numbers Random r; … r = new Random(); … = r.Next(1, 4); // values 1 to 3 = r.Next(-100, 100); //values -100 to 99 = r.Next(100) //values 0 to 99

  10. List<T> List<> is a parameterized collection class that is useful for storing dynamic collections of items; use the Add, Remove, RemoveAt, etc. methods falling_food = new List<FoodItem>(); … falling_food.Add(fi);

  11. Tutorial Link Tutorial courtesy of Dr. J. Preston. audio/video tutorials cse1302_Lecture4_FoodWars.zip