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

class 3 july 14 2010 create new project
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Class #3: July 14, 2010

slide-2
SLIDE 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

slide-3
SLIDE 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.

slide-4
SLIDE 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.

slide-5
SLIDE 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.

slide-6
SLIDE 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.

slide-7
SLIDE 7

Game1 class

 GraphicsDeviceManager graphics;

 Handles the management of the graphics device, or what is

  • utput 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.

slide-8
SLIDE 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

  • f its classes.

 Today we will be using Vector2 and Texture2D

slide-9
SLIDE 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;

slide-10
SLIDE 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”);

slide-11
SLIDE 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();

slide-12
SLIDE 12

Yesterday’s Answers

slide-13
SLIDE 13
slide-14
SLIDE 14