This project is read-only.

To setup the InputHelper, you have the option to have the GameComponent update it for you or you update everything yourself.

To have the GameComponent update it for you then simply add this line to your game constructor.
Components.add(new XnaInputHelperComponent(this, true);
This will have the GameComponent update the InputHelper by platform. So if you are in a Windows game then it will Update the Mouse and Keyboard.
And if you are on the Xbox it will update the Gamepad and the Chatpad.

Components.add(new XnaInputHelperComponent(this, true,true,true,true)
This constructor will let you choose what Inputs you want updated. It shows up in Intellisense but I will list which one is wich.
  • Game - just pass this
  • UpdateKeyboard - boolean
  • UpdateMouse - (boolean*
  • UpdateGamePad - boolean
  • UpdateChatPad - boolean

Now for the final option. you don't even have to use the XnaInputHelperComponent. You can just manually update all of the input methods with...
  • InputHelper.UpdateKeyboard();
  • InputHelper.UpdateMouse();
  • InputHelper.UpdateGamepad();
  • InputHelper.UpdateChatpad();

Once you have chosen how the InputHelper will be updated you can use the InputHelper class however you want.

A quick overview.

The InputHelper class contains an accessor to each type of Input.
So if you wanted to access the Keyboard you would do this...

After that there are a bunch of functions that intellisense will help you with. They are all fairly straightfoward and return a boolean value.
So say I wanted to see if the A key was down.
I would call this in my Update Loop

protected override void Update(GameTime gameTime)
          Console.WriteLine("The A Key is down");

That's basically it. All the functions are pretty straightfoward. All classes (except the mouse) share the same setup. So getting a KeyPress in
the Keyboard class you would just do
And for the Gamepad class you would do.

If you have been using the InputHelper that is in the full XnaHelpers Library. Then there are some changes in the Gamepad class.
There are now only 2 overloads for the IsButtonDown, IsButtonPressed, IsButtonUp.
One of them works the same way as before, you simply pass a PlayerIndex, and a button.
In the new overload you pass an Array of player indexes and a Button. If any of the Indexes passed have that specified button pressed,down or up, whichever action your testing for. It will return true.
So if you pass it PlayerIndexes 1 - 4 and controller 2 has the button down but none of the others do it will still return true.

Last edited Jul 22, 2010 at 5:58 PM by Destroyer229, version 3


No comments yet.