Search in sources :

Example 1 with Controller

use of com.badlogic.gdx.controllers.Controller in project libgdx by libgdx.

the class ControllersTest method initialize.

private void initialize() {
    if (initialized)
        return;
    // print the currently connected controllers to the console
    print("Controllers: " + Controllers.getControllers().size);
    int i = 0;
    for (Controller controller : Controllers.getControllers()) {
        print("#" + i++ + ": " + controller.getName());
    }
    if (Controllers.getControllers().size == 0)
        print("No controllers attached");
    // setup the listener that prints events to the console
    Controllers.addListener(new ControllerListener() {

        public int indexOf(Controller controller) {
            return Controllers.getControllers().indexOf(controller, true);
        }

        @Override
        public void connected(Controller controller) {
            print("connected " + controller.getName());
            int i = 0;
            for (Controller c : Controllers.getControllers()) {
                print("#" + i++ + ": " + c.getName());
            }
        }

        @Override
        public void disconnected(Controller controller) {
            print("disconnected " + controller.getName());
            int i = 0;
            for (Controller c : Controllers.getControllers()) {
                print("#" + i++ + ": " + c.getName());
            }
            if (Controllers.getControllers().size == 0)
                print("No controllers attached");
        }

        @Override
        public boolean buttonDown(Controller controller, int buttonIndex) {
            print("#" + indexOf(controller) + ", button " + buttonIndex + " down");
            return false;
        }

        @Override
        public boolean buttonUp(Controller controller, int buttonIndex) {
            print("#" + indexOf(controller) + ", button " + buttonIndex + " up");
            return false;
        }

        @Override
        public boolean axisMoved(Controller controller, int axisIndex, float value) {
            print("#" + indexOf(controller) + ", axis " + axisIndex + ": " + value);
            return false;
        }

        @Override
        public boolean povMoved(Controller controller, int povIndex, PovDirection value) {
            print("#" + indexOf(controller) + ", pov " + povIndex + ": " + value);
            return false;
        }

        @Override
        public boolean xSliderMoved(Controller controller, int sliderIndex, boolean value) {
            print("#" + indexOf(controller) + ", x slider " + sliderIndex + ": " + value);
            return false;
        }

        @Override
        public boolean ySliderMoved(Controller controller, int sliderIndex, boolean value) {
            print("#" + indexOf(controller) + ", y slider " + sliderIndex + ": " + value);
            return false;
        }

        @Override
        public boolean accelerometerMoved(Controller controller, int accelerometerIndex, Vector3 value) {
            // not printing this as we get to many values
            return false;
        }
    });
    initialized = true;
}
Also used : PovDirection(com.badlogic.gdx.controllers.PovDirection) ControllerListener(com.badlogic.gdx.controllers.ControllerListener) Vector3(com.badlogic.gdx.math.Vector3) Controller(com.badlogic.gdx.controllers.Controller)

Example 2 with Controller

use of com.badlogic.gdx.controllers.Controller in project libgdx by libgdx.

the class Lwjgl3ControllerManager method pollState.

void pollState() {
    for (int i = GLFW.GLFW_JOYSTICK_1; i < GLFW.GLFW_JOYSTICK_LAST; i++) {
        if (GLFW.glfwJoystickPresent(i)) {
            boolean alreadyUsed = false;
            for (int j = 0; j < controllers.size; j++) {
                if (((Lwjgl3Controller) controllers.get(j)).index == i) {
                    alreadyUsed = true;
                    break;
                }
            }
            if (!alreadyUsed) {
                Lwjgl3Controller controller = new Lwjgl3Controller(this, i);
                connected(controller);
            }
        }
    }
    polledControllers.addAll(controllers);
    for (Controller controller : polledControllers) {
        ((Lwjgl3Controller) controller).pollState();
    }
    polledControllers.clear();
}
Also used : Controller(com.badlogic.gdx.controllers.Controller)

Example 3 with Controller

use of com.badlogic.gdx.controllers.Controller in project nhglib by VoidZombie.

the class InputHandler method dispatchStickInputs.

private void dispatchStickInputs() {
    Array<Controller> availableControllers = Controllers.getControllers();
    for (int id = 0; id < availableControllers.size; id++) {
        Controller controller = availableControllers.get(id);
        if (controller != null) {
            Array<NhgInput> stickInputs = stickInputsMap.get(id);
            if (stickInputs != null) {
                for (NhgInput input : stickInputs) {
                    if (input != null && isValidInput(input)) {
                        processStickInput(id, controller, input);
                        dispatchStickInput(input);
                    }
                }
            }
        }
    }
}
Also used : Controller(com.badlogic.gdx.controllers.Controller)

Aggregations

Controller (com.badlogic.gdx.controllers.Controller)3 ControllerListener (com.badlogic.gdx.controllers.ControllerListener)1 PovDirection (com.badlogic.gdx.controllers.PovDirection)1 Vector3 (com.badlogic.gdx.math.Vector3)1