Working with the XBox360 analog sticks

Hello,

I’m working with jinput to access my 360 controller, and have nearly everything working properly. However, one question: with the two analog sticks, the way that I am currently accessing them only sends information back to the application when the stick’s value changes. So, if I hold a stick in the same position (be it 1, -1, .423162346 or whatever else) no continuous data stream is sent back to the application.

How would I go about allowing for that?

My current code looks something like this:


        Controller[] ca = ControllerEnvironment.getDefaultEnvironment().getControllers();

        for(int i =0;i<ca.length;i++){
            //If controler is a gamepad, name it xbox
            if (ca[i].getType() == Controller.Type.GAMEPAD) {
                xbox = ca[i];
            }
        }

        while (true) {
                xbox.poll();
                EventQueue queue = xbox.getEventQueue();
                Event event = new Event();

                while (queue.getNextEvent(event)) {
                    Component comp = event.getComponent();
                    float value = event.getValue();
                    
                    //Code to handle other buttons...

                    if (comp.getName().equals("X Axis")) {
                         //Take action off the value
                    }
                   
                    //Code to handle other buttons

            }

Thanks for any help you can offer.

The easiest way is to record the value when it changes in a variable, and use that in your update code.

The way I use it is instead of moving say a character by the value of the axis at every game tick, set the speed of the character from the axis event, then use the speed in each game tick.

HTH

Endolf