Difference between revisions of "Game Programming Class2"

esse quam videri
Jump to: navigation, search
(SVN Checkout)
Line 104: Line 104:
==Inclass Keyboard input demo==
KeyboardState keyboardState = Keyboard.GetState();
input from Game Controller and Keyboard
XNA has built in support for up to 4 game controllers. The default controller is a x-box controller.
X-Box Controller The Controller is accessed through the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepad.aspx GamePad] Object and the [http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.gamepadstate_members.aspx GamePadState] Structure reference types
        //Get an instance of the gamePadState Structure
        GamePadState gamePad1State = GamePad.GetState(PlayerIndex.One);
/*Since the Keyboard structure is Windows only we
need to use some preprocessor
directives to only compile the KeyBoard
state code if the target is not XBOX360 (I
should also add zune if this is one of our build targets)
        #if !XBOX360
            #region KeyBoard
            KeyboardState keyboardState = Keyboard.GetState();
Angle Measured in Radians
using [http://msdn.microsoft.com/en-us/library/system.math.atan2.aspx atan2] to get the angle from the direction vector
        GamePad.SetVibration(PlayerIndex.One, 1.0f, 1.0f);  //left low freq motor right high freq motor

Revision as of 15:42, 1 February 2011


free game fonts XNA Redistributable Font Pack

Fun with Fonts in XNA

note this font pack is now included in XNA 4

SVN Checkout

All of the examples for this class and the basic game library we wil be building is in our SVN repo this week we'll practice checking out a folder from the repo.


new Repo for XNA4



tortoisesvn http://tortoisesvn.tigris.org/

ankhsvn http://ankhsvn.open.collab.net/

in class

Spritefont demo

IntroFonts/Game1.cs IntroFonts.zip

XNA Structures

Game Class

The XNA Game class has two private properties

  • GraphicsDeviceManager graphics;
  • ContentManager content;
//the game constuctor can be used to set some graphics settings.
graphics.PreferredBackBufferHeight = 768;
graphics.PreferredBackBufferWidth = 1024;
//graphics.PreferredBackBufferHeight = 1080;
//graphics.PreferredBackBufferWidth = 1920;
//graphics.IsFullScreen = true;

  1. Declare SpriteBatch spriteBatch;
  2. Initialize()
  3. LoadContent()
  4. UnloadContent()
  5. Update(GameTime gameTime)


FrameRate and GameTime

Time and Timespan

Example of update using GameTime to calculate elapsed time

  • IntroSimpleSpriteUpdateWindows.zip
  • IntroSimpleSpriteWindows/Game1.cs

Understanding GameTime We'll revisit game time when we talk about performance profiling.

  1. Draw(GameTime gameTime)

Console And Trace

We will build a console class later and debug in game.

Texture2D and SpriteBatches

2D Graphics Overview

About textures and Batching

Displays, ViewPorts, Client Bounds

Alpha channels



demo project

  • IntroSimpleSpriteBatchOptionsWindows.zip



  1. Options SpriteBlendMode
  2. Additive Enable additive blending. http://blogs.msdn.com/etayrien/archive/2006/12/19/alpha-blending-part-3.aspx
  3. AlphaBlend Enable alpha blending. http://blogs.msdn.com/etayrien/archive/2006/12/19/alpha-blending-part-2.aspx
  4. None No blending specified.

Other Projects

IntroSimpleSpriteUpdateGravityWindows.zip IntroSimpleSpriteUpdateWindows.zip


  • XNA Picture With Update
Update your picture to include some movement with the update method. Use the keyboard or mouse to interact with something on the screen
  • Read Chapter 2 in XNA 3.0
  • Read Chapter 4 in XNA 3.0 (yes we skipped 3 we'll come back)