0
\$\begingroup\$

So just a little bit of XNA code:

if (this.IsActive && (Keyboard.GetState().GetPressedKeys().Length > 0 || Mouse.GetState().LeftButton == ButtonState.Pressed || Mouse.GetState().RightButton == ButtonState.Pressed || Mouse.GetState().MiddleButton == ButtonState.Pressed) || GP_state.GetButton(8) == ButtonState.Pressed)
                    {
                        Current_GameState = GameStates.Game;
                            bg_music.Play();
                    }

If something is done --> Switch to a different game state. Works with: Keyboard and Mouse, but not with the gamepad (which is new and it works with other games) So why does XNA not recognise it correctly??

EDIT: I do have a working solution and mark my own answer as soon as possible as right...

\$\endgroup\$
  • \$\begingroup\$ Found out how it works... It is indeed not supported: Tutorial: miszalok.de/C_3D_XNA/C4_Controller/XNAC4_GamePad_e.htm Needed .dll: sourceforge.net/projects/xnadirectinput Sorry, unable to answer my question within 7 hours. \$\endgroup\$ – Florian Reisinger Mar 23 '13 at 18:16
  • \$\begingroup\$ We aren't talking about an XBox controller then? If it is an XBox controller then just check for a button being pressed. \$\endgroup\$ – Dialock Mar 23 '13 at 18:46
  • \$\begingroup\$ Yes "controler" is a very general term... Please see this part of the code: "GamePad.GetState(PlayerIndex.One).IsConnected" The program does something, if a Gamepad (which has to be a XBox controller) is connected. \$\endgroup\$ – Florian Reisinger Mar 24 '13 at 7:06
  • \$\begingroup\$ I see your code and it makes no sense. 1: It's Microsoft, so no out of box support for controllers except their own. 2: design wise you should be checking if a button was pressed, not if the controller is/was connected. Logic is similar to your checks on the keyboard and mouse. \$\endgroup\$ – Dialock Mar 24 '13 at 16:57
  • \$\begingroup\$ Well, I want to check if the framework works. Anyway I am going to update my code to satisfy you.... \$\endgroup\$ – Florian Reisinger Mar 25 '13 at 6:39
1
\$\begingroup\$

Well, found out, that is indeed not supported, but found the following: http://nuclexframework.codeplex.com/releases/view/62687 <-- Only Nuclex.Input.dll is needed to Reference...

How to use:

  1. Class level variable: InputManager ManageI;
  2. List item On Initialize() or in the Game Constructor:ManageI = new InputManager();
  3. 2 Using needed: using Nuclex.Input; using Nuclex.Input.Devices;
  4. Before trying to get a gamestate, don't forget to call ManageI.Update();

Because I am only developing for Desktop, I have no idea how you are able to use it on a XBox or Windows Phone 7 (well, of course there are .dlls included....) and why you should...

For testing the joystick I can recommend: http://sandbox.yoyogames.com/games/155175-joystick-input-tester-v100

| improve this answer | |
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.