Posts Tagged sample

Action Based Input Manager w/Events in XNA

I recently completed an action based Input system for my own engine that allows me to create named actions which support the GamePad, Keyboard and Mouse.

The system uses events to notify the game of changes in input state, which makes it really easy to use, and the system supports XML serialisation so key assignments can be saved and loaded.

Supports:

  • Thumbsticks (Analog)
  • Triggers (Analog)
  • GamePad Buttons (incl Trigger “Buttons”)
  • Keyboard
  • Mouse (Analog)
  • Mouse Buttons

The system also supports Gamepad, Mouse and Keyboard assignments for each action, so you can support both the GamePad and Keyboard at the same time.

It also supports disabling of certain GamePads, so you can find the active GamePad and only accept input from that one, via a really simply array of booleans.

You can specify a single direction or axis for the Thumbstick and Mouse, so that the events will only be triggered if there is movement “up” on the Thumbstick.

You can download the InputManager and InputAction classes below:

AxialInput Sample

Feel free to use these classes in your own project, although if you do make use of them, it would be nice to get a mention.

If you notice any problems, or have any suggestions/feedback, feel free to post them in the comments.

Note/Disclaimer:
This sample/code is provided as is. I am not responsible for any problems you may have, and you use the code at your own risk.
I am available to answer questions about the code through the comment system on this website – although this is not guaranteed.
This code was intended for personal use, however I have decided to share it with the community to help out newer developers.

, ,

View Comments