How to support multiple input devices

Started by
0 comments, last by Gavin Williams 11 years, 9 months ago
I'm currently developing a PC game with the assistance of XNA and I'm integrating keyboard and gamepad control support. Up until now I've only supported gamepad control, and finding an elegant way to allow the player to choose one or the other is posing a complicated task to resolve.

I was thinking of creating a class that would sort of convert either input into a universal sort of data that the game could then use for the player's character and the rest of the game to interpret- but I don't exactly know what that might look like, and I don't know where to start?

Then, I thought maybe it would be simpler to create a duplicate of my main character's class, except adjust it to respond to keyboard input instead of gamepad input.

Can anybody offer any insight?
Advertisement
You can just write your input handling code however you want. Gather your keyboard input, then gather your gamepad input. They can each call your character's movement methods if you are using direct control or they can each issue their own commands (in a scripting system) or in a command pattern. Another way is to have each input device output game-effect structs and define their addition in order to resolve conflicts or differences, this can be all done in the struct, which sounds like your idea of having a universal data representing your game commands.

You can have an interpreting class as you thought as well, I've done that before and just passed my mouse/keyboard data into it where it can be made sense of in game terms. I'd say use a method that you are comfortable with and just try to make it work as best you can.

This topic is closed to new replies.

Advertisement