User Input XNA Programming 14April2009

Thanks for your help last Thursday with the Xbox 360 systems in GMCS 425. We will meet in GMCS 425 again this coming Thursday, as I feel all the update and network issues will have been worked out.

FYI - Each system [xbox00 (instructor), xbox01, xbox02, ... xbox07] is being set up with its own XBOX Live Golden account using the User ID xboxcs00@rohan.sdsu.edu, ..., xboxcs07@rohan.sdsu.edu.

Topic for today - User Input with XNA for console [xbox360] and/or system [PC] game development.

Proquest/Safari access to XNA Game Studio 3.0 Unleasher
Chapter 5 covers input devices

Dr. Dobb's Portal "Using XNA Input for Controllers" (print view) Web www.ddj.com/windows/201803739

Chapter 2 of our textbook introduced Game Input (pp. 32-41) for the keyboard, mouse, audio of a game. The General Game Structure (p. 8)


General Game Structure
The central logic for every game includes preparing the environment where the game will
run, running the game in a loop until the game ending criteria ismet, and cleaning up
the environment.
The idea of having themain programlogic running in a loop is crucial for a game,
because the game needs to keep running whether or not it has user interaction. This
doesn’t happen with some commercial applications, which only do something in
response to user input.
The following pseudocode presents a simplified game structure, including the game
loop:
Initialize graphics, input and sound
Load resources
Start game loop. In every step:
Gather user input
Perform needed calculations (AI, movements, collision detection, etc.)
Test for game ending criteria – if met, stop looping
Draw (render) screen, generate sounds and game controller feedback
Finalize graphics, input, and sound
Free resources"


and the Game Loop (p. 13)
Game Loop
Most of the game processing occurs inside the game loop. It’s here where the game
checks if there is player input to process, the game characters’ artificial intelligence is calculated,
the game components’movements are executed, the collisions between them
are considered, the game ending criteria is checked, and finally, where the controller
vibration is activated, the sound is played, and the screen is drawn.
The Microsoft.Xna.Framework.Game class provides two overridablemethods that the
internal game loop calls: Update, where youmust include the game calculations, and Draw,
where you draw the game components. Let’s take a closer look at thesemethods, presented
in the next code snippet, to highlight some relevant details:
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
ButtonState.Pressed)
this.Exit();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
}

In Chapter 3 the use of user input from the Game Controller was further examined for the 2d game with teh Xbox Controller providing guidance for the movement of the space ship.

http://blogs.msdn.com/devschool/Default.aspx?p=3
Sam Stokes lists as his "Week 9" activity to handle input devices.

creators.xna.com/en-US/utilities/inputreporter
The Input Reporter utility

Description:

This utility reports all GamePad state and capability data available via the XNA Framework.

Utility Overview

The GamePad type provided by the XNA Framework provides an API to poll the state and capabilities of compliant devices that are connected to the computer or Xbox 360, supporting up to four concurrent controller connections. All compliant accessories, such as the Xbox 360 Wireless Racing Wheel, fill the same GamePadState and GamePadCapabilities structures as the Xbox 360 Controller.

This utility displays this data for all controllers connected to the system. The display updates as controllers are used, connected, and disconnected. The Ring of Light graphic at the top-right corner of the screen shows which controllers are connected. The numerals around the Ring of Light indicate which controller is currently being displayed. The active controller is switched by pressing any of the digital buttons on the controller you wish to switch to. The labels and GamePadType data provided match the method and enumeration names provided by the XNA Framework for easy correlation. Values that are not supported, according to the GamePadCapabilities structure, are dimmed.

Since all of the GamePadState values are displayed as data, it would have been frustrating to map any of them directly to an action, such as the BACK button immediately exiting the application. Input Reporter implements a "charging switch" that triggers an action after a button is held down for several seconds, allowing the user to test the controllers without immediately controlling the application.

A common use of this utility is to investigate how the controls provided by various accessories map to the GamePadState and GamePadCapabilities values.