This is more of an overview of the InputManager class but they are basically one in the same.

I will NOT be listing every method/accessor/variable as it would take up more space and time than its worth but I will show how to use them as most of them follow the same structure.

All input is contained and updated inside of the InputManager class.
There are 4 classes that is uses that you technically can access but should not be used unless it is being adapted to your own needs.
Inside the InputManager everything is public, so if you want you can change all of the values manually, it is not recommended but if you find yourself needing to there won't be any access modifiers stopping you.

So say we wanted to get input from the keyboard, assuming we are using the XnaHelpersComponent we would call....
InputHelper.Keyboard
This will give us access to a bunch of methods and variables to make the keyboard easier.
All of the Input classes share the same idea (except the Mouse class, it is setup differently but just as easy)

Say we want to see if the user Pressed the key but did not hold it, or even if they did hold it it only performs the action once per key press, ideal for menu systems.

In our games update we would have
InputHelper.Keyboard.IsKeyPressed(Keys.Space))
{
//Insert code here
}

There is also
InputHelper.Keyboard.IsKeyDown(Keys.Space))
Which will fire each frame that the key is pressed, which can be good or bad depending on what your doing so just remember
Pressed is once per key press, Down is once per frame while the key is down.

There are other methods and accessors but they are fairly self explanatory so I won't go into them.

The same rules that go for keyboard apply to the GamePad* and ChatPad the chatpad in particular is nearly identical to the Keyboard class since its just a keyboard that has a PlayerIndex assigned to it.

Ill go over getting some input with the GamePad, Chatpad and then a little bit about the mouse.

A few notes about the GamePad first
There are several overloads for each IsButtonDown and IsButtonPressed along with IsButtonUp.
The main arguments include a PlayerIndex and a Button to check for.
Some overloads however
Contain 2 PlayerIndexes and One button argument. This is a ranged check. I'm not sure how useful it is but I threw it in there anyway. Basically what it does it checks each PlayerIndex passed and sees if the Button is pressed or down or whatever your checking for, and will return true if ALL of the passed PlayerIndexes meet the requirement. So if I called.

InputHelper.GamePad.IsButtonPressed(PlayerIndex.One, PlayerIndex.Four, Buttons.Start)
This will return true if the PlayerIndexes between 1 and 4 have the start button pressed.
NOTE
Since input is on a frame by frame basis it is a better idea to use IsButtonDown for this sort of thing since most people are going to have a hard time getting everyone to press the button at the exact frame.

Quick bit on the chatpad
In case anyone is wondering the chatpad is the keyboard attachment for the Xbox 360 controller.
Basically works the same way as the keyboard but here are some examples.
if(InputHelper.ChatPad.IsKeyDown(Keys.A))
{
//Code
}

if(InputHelper.ChatPad.IsKeyPressed(Keys.B))
{
//Code
}
Basically all there is to it.

Now some info about the mouse
The mouse is little bit more complicated.
Unlike the Keyboard and GamePad classes there is no enumerator that holds all the possible Mouse buttons or mouse actions.
Instead they have to be hardcoded, E.G a method for each action. There are alot of functions and variables so I won't go into detail on all of them but intellisense will help you mostly I will give you an overview of how to use it and things to watch out for.

Unlike GamePad and Keyboard there is no function like IsMouseDown(MouseButton button)
They look more like...
LeftMouseButtonDown()
LeftMouseButtonPressed()
and so forth.

There are also more accessors than in Keyboard and Gamepad.
You can access things like the mouse position, the underlying MouseState and a value defining the scroll wheel.
Note about the scroll wheel
The scroll wheel value returned is NOT how much the scroll wheel was turned that frame, it is a cumulative value so you have to find some way to break it down to a frame by frame basis.

That's basically it for the InputHelper class, hopefully this gives you some helpful information on how to use it, most if it is fairly straight forward thanks to intellisense.

Again there are multiple ways of accessing the InputManager class ill go over them again real fast.

If your using the XnaHelpersComponent
InputHelper.Keyboard
InputHelper.Mouse
InputHelper.GamePad
InputHelper.ChatPad

If your using the InputManager Component
Input.Keyboard
Input.Mouse
Input.GamePad
Input.ChatPad



Last edited Jul 27, 2010 at 9:45 PM by Destroyer229, version 3

Comments

No comments yet.