Slick Forums
http://slick.ninjacave.com/forum/

BUG: Controller Input
http://slick.ninjacave.com/forum/viewtopic.php?f=4&t=3132
Page 1 of 1

Author:  Blu3 [ Sun Mar 20, 2011 6:55 pm ]
Post subject:  BUG: Controller Input

Code:
   public void update(GameContainer container, int delta) throws SlickException
   {
      System.out.println(Controllers.getController(0).getName());
      System.out.println(Controllers.getController(0).getXAxisValue());
      System.out.println(Controllers.getController(0).getYAxisValue());
      
       Controller[] cons = ControllerEnvironment.getDefaultEnvironment().getControllers();
       for (Controller c : cons)
       {
          if (c.getName().contains("USB"))
          {
             for (net.java.games.input.Component ca : c.getComponents())
             {
                if (ca.getName().contains("X Axis") || ca.getName().contains("Y Axis"))
                {
                   System.out.println(ca.getPollData());
                }
             }
          }
       }
   }


getXAxisValue() and getYAxisValue() return -1 at the start of the game. When i click the corresponding direction once, they return 0.

If i use Jinput directly, it returns the correct value.

Tested with 3 different joysticks

The example above outputs the following at the start of the program:

Code:
USB Joystick     
-1.0
-1.0
-1.5258789E-5
-1.5258789E-5


If i press the direction, as said, it outputs:

Code:
USB Joystick     
0
0
-1.5258789E-5
-1.5258789E-5


Not sure whether it's a LWJGL problem or Slick messing up some LWJGL input initialization.[/quote]

Author:  R.D. [ Sun Mar 20, 2011 7:17 pm ]
Post subject: 

Sry i don't get it jet.
Why not using the Input class from the container?

Author:  Blu3 [ Sun Mar 20, 2011 7:23 pm ]
Post subject: 

R.D. wrote:
Sry i don't get it jet.
Why not using the Input class from the container?


Because it results in the same error. If you implement InputProvider

Code:
   @Override
   public void controlPressed(Command command)
   {
      System.out.println("Pressed:" +command);
   }


Gets called without a button being pressed.

Author:  Blu3 [ Sun Mar 20, 2011 7:42 pm ]
Post subject: 

arg crap double post

Or if you try input.isControlPressed it also displays the wrong results unless a button on the joystick has been pressed.

Author:  R.D. [ Mon Mar 21, 2011 6:32 am ]
Post subject: 

Why InputProvider?

You can easily use container.getInput(). Which is the recommended way for controller input :D
Also there you just check if isControllerLeft(). If this is not working than you might have a broken controller.

Author:  Blu3 [ Mon Mar 21, 2011 11:09 am ]
Post subject: 

R.D. wrote:
Why InputProvider?

You can easily use container.getInput(). Which is the recommended way for controller input :D
Also there you just check if isControllerLeft(). If this is not working than you might have a broken controller.


That's what i was trying to say in my first post. No matter what slick utility you use or even what kind of lwjgl class you use, you get the wrong results.

I start the programm, isControllerLeft() gives me -1.0. I press LEFT on my Controller, it says that Left just got released and gives me 0.0 and works properly afterwards.

Author:  kevglass [ Sun Apr 10, 2011 4:14 pm ]
Post subject: 

Controllers is part of LWJGL not Slick?

Kev

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/