Generalizing Controller Input

 Posted by at 12:09 am  XNA DotA
Dec 242010
 

For quite projects now I’ve been trying to use a single Input Class to handle all user input. The overall goal for this class is to have the ability to drag and drop the class from project to project with minimal changes. This also allows changes to the controls without having to go into each object to update a control system change.

For now input is hardcoded to each function, W is always ActorUp, at somepoint it would be nice to modify the class so the user can custom controls as they see fit. Controller actions string might be a good idea to include in the class as well, so it can easily be edited per project, maybe with an easy way to draw the controller scheme within the game itself.

The base of the InputManager class is from the RPG Game at the App Hub. Each action can be defined in the enumeration the class has, from there each action is paired up with key mappings. The game then calls IsActionPressed(Action), to trip the code related to that action. The thing I like about this class is how separate the  input is from the game. The game should only call upon actions, making for very quick modifications to how the input is specifically handled with changes to the InputManager class. The one down size to the class is how many areas the action covers, I would love to find a way to tweak it, so the enumeration  contains the action, action name, and mappings are all contained together.

The list of input actions

  • Menu Based
    • MenuUp
      • LeftThumbStickUp
      • DpadUp
      • W
      • (Up)
  • MenuDown
    • LeftThumbStickDown
    • DpadDown
    • S
    • (Down)
  • MenuLeft
    • LeftThumbStickLeft
    • DpadLeft
    • A
    • (Left)
  • MenuRight
    • LeftThumbStickRight
    • DpadRight
    • D
    • (Right)
  • MenuAccept
    • ControllerA
    • Enter
    • (M)
  • MenuBack
    • ControllerB
    • Escape
    • (K)
    • Game Base
      • ActorMovement
        • LeftThumbStick
        • WASD
  • CameraMovement
    • RightThumbStick
    • Up, Down, Left, Right
  • ToggleDebug
    • ~ (Keyboard only)
  • Controller <> Keyboard
    • LeftThumbStick <> WASD
    • Dpad <> WASD or Up, Down, Left, Right or 1,2,3,4
    • RightThumbStick <> Up, Down, Left, Right
    • ControllerA <> M
    • ControllerB <> K
    • ControllerY <> J
    • ControllerX <> N
    • Start <> Enter
    • Back <> Esacpe
    • LeftTrigger <> Left Control
    • RightTrigger <> Right Control
    • LeftBumper <> Left Shift
    • RightBumper <> Right Shift
    • LeftThumbClick <>
    • RightThumbClick <>