XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

User Defined Controls varying over 3 formats (Gamepad, Keyboard, Mouse)

Last post 5/5/2008 6:41 PM by Lord Ikon. 5 replies.
  • 5/3/2008 6:10 PM

    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.

    XNA is Shawn's game. We just play it.

    foreach (Day day in life) { experience++; }
  • 5/3/2008 7:27 PM In reply to

    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]

  • 5/3/2008 8:03 PM In reply to

    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...

    XNA is Shawn's game. We just play it.

    foreach (Day day in life) { experience++; }
  • 5/3/2008 8:05 PM In reply to

    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.

    XNA is Shawn's game. We just play it.

    foreach (Day day in life) { experience++; }
  • 5/3/2008 8:31 PM In reply to

    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]

  • 5/5/2008 6:41 PM In reply to

    Re: User Defined Controls varying over 3 formats (Gamepad, Keyboard, Mouse)

    The files in this directory might be of some help. We execute all input through messages.

    http://quickstartengn.svn.sourceforge.net/viewvc/quickstartengn/trunk/framework/code/Common/Input/

    Alternatively, if you'd like you can download the engine if you'd like to see it in action, it in in the link in my sig. Make sure to get v0.19. v0.182 does not have this.

    XNA QuickStart Engine (3D Game Engine for XNA) | My site
    "I'll be whatever I want to do!", Philip J. Fry
Page 1 of 1 (6 items) Previous Next