Game Programming Class3

esse quam videri
Revision as of 08:07, 18 January 2009 by Akelly (talk | contribs)
Jump to: navigation, search

Class 3 Input Handling


free game fonts XNA Redistributable Font Pack

Fun with Fonts in XNA

in class

Spritefont demo



input from Game Controller and Keyboard

GamePad XBoxGamePadWithLabels.png

XNA has builtin support for up to 4 game controllers. The default controller is a x-box controller. X-Box Controller The Controller is accessed through the GamePad Object and the GamePadState Structure reference types <csharp>

        //Get and 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

        #if !XBOX360
           #region KeyBoard
           KeyboardState keyboardState = Keyboard.GetState();


Angle Measured in Radians

using 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


Classes and Generics

Shooting with pacman

in class

PacMan Project with input


  • Create an XNA project that uses the Keyboard for input.
  • Chapter 5 in XNA Game Studio 2.0 Writing Text
  • Chapter 7 in XNA Game Studio Express