-
|
|
User Defined Controls varying over 3 formats (Gamepad, Keyboard, Mouse)
|
Hi guys,
Im in need of a little assistance!
I am trying to write a small game engine for myself and maybe a few friends to use, and im trying to set up a subclass to store keys/buttons/mouseButtons in variables. like so:
public class Controls { public Keys forward, backward, strafeLeft, strafeRight, turnLeft, turnRight, lookUp, lookDown; }
But i need these variables to be able to accept keyboard keys, gamepad buttons and mouse buttons as values.
Does anybody know how to do this, and/or if its even possible?
Regards,
M@t.
|
|
-
|
|
Re: User Defined Controls varying over 3 formats (Gamepad, Keyboard, Mouse)
|
Create a generic control class, then derive from this class to create classes for keyboard, gamepad, and mouse buttons. Then where you need a button control in your game, use a variable of the type of the generic control and you can assign any of the derived classes to the variable. You'll need a way to update the derived classes by calling the appropratie GetState method. It gets a bit hairier if you want to also include thumbsticks, triggers, and mouse axis movements, but I use a system like this for the project I'm working on.
Good judgment comes from experience, and experience comes from bad judgment. -- Barry LePatner Sixty years ago I knew everything; now I know nothing; education is a progressive discovery of our own ignorance. -- Will Durant, American philosopher/author [1885-1981]
|
|
-
|
|
Re: User Defined Controls varying over 3 formats (Gamepad, Keyboard, Mouse)
|
Ive already thought of that, and thumsticks etc arent a problem via this:
backward = Buttons.LeftThumbstickDown;
but what im trying to be able to do is for example:
take the variable "shoot", this requires different types for each input, albeit gamepad, keyboard+mouse or keyboard only. but lets just say we are using a keyboard and mouse. the programmer who uses my engine will be able to set the shoot variable to whatever key they wish. it could be Keys.Space or it could be the mouse LeftButton. It all depends on what the programmer using the engine wants. they could even use the A,B,X,Y buttons on the gamepad for movement if they felt like it. Im just stuck as to how to implement this over the various formats...
|
|
-
|
|
Re: User Defined Controls varying over 3 formats (Gamepad, Keyboard, Mouse)
|
wait a sec... you mean instanciate a new class for every variable... hmmm ill have to give this some thought. it may proove promising, but then again it may not just as easily... ill try to see if i can implement this...
Thanks!
M@t.
|
|
-
|
|
Re: User Defined Controls varying over 3 formats (Gamepad, Keyboard, Mouse)
|
Exactly. Each "button" is an instance of a class derived from the generic control class. The key (or gamepad button, or mouse button) to be used for that instance is passed to the constructor when the class is instantiated.
Good judgment comes from experience, and experience comes from bad judgment. -- Barry LePatner Sixty years ago I knew everything; now I know nothing; education is a progressive discovery of our own ignorance. -- Will Durant, American philosopher/author [1885-1981]
|
|
-
|
|
Re: User Defined Controls varying over 3 formats (Gamepad, Keyboard, Mouse)
|
|
|
|