Search in sources :

Example 1 with Gamepad

use of com.badlogic.gdx.controllers.gwt.support.Gamepad in project libgdx by libgdx.

the class GwtControllers method onGamepadUpdated.

@Override
public void onGamepadUpdated(int index) {
    Gamepad gamepad = Gamepad.getGamepad(index);
    GwtController controller = controllerMap.get(index);
    if (gamepad != null && controller != null) {
        // Determine what changed
        JsArrayNumber axes = gamepad.getAxes();
        JsArrayNumber buttons = gamepad.getButtons();
        synchronized (eventQueue) {
            for (int i = 0, j = axes.length(); i < j; i++) {
                float oldAxis = controller.getAxis(i);
                float newAxis = (float) axes.get(i);
                if (oldAxis != newAxis) {
                    GwtControllerEvent event = eventPool.obtain();
                    event.type = GwtControllerEvent.AXIS;
                    event.controller = controller;
                    event.code = i;
                    event.amount = newAxis;
                    eventQueue.add(event);
                }
            }
            for (int i = 0, j = buttons.length(); i < j; i++) {
                float oldButton = controller.getButtonAmount(i);
                float newButton = (float) buttons.get(i);
                if (oldButton != newButton) {
                    if ((oldButton < 0.5f && newButton < 0.5f) || (oldButton >= 0.5f && newButton >= 0.5f)) {
                        controller.buttons.put(i, newButton);
                        continue;
                    }
                    GwtControllerEvent event = eventPool.obtain();
                    event.type = newButton >= 0.5f ? GwtControllerEvent.BUTTON_DOWN : GwtControllerEvent.BUTTON_UP;
                    event.controller = controller;
                    event.code = i;
                    event.amount = newButton;
                    eventQueue.add(event);
                }
            }
        }
    }
}
Also used : Gamepad(com.badlogic.gdx.controllers.gwt.support.Gamepad) JsArrayNumber(com.google.gwt.core.client.JsArrayNumber)

Example 2 with Gamepad

use of com.badlogic.gdx.controllers.gwt.support.Gamepad in project libgdx by libgdx.

the class GwtControllers method onGamepadConnected.

@Override
public void onGamepadConnected(int index) {
    Gamepad gamepad = Gamepad.getGamepad(index);
    GwtController controller = new GwtController(gamepad.getIndex(), gamepad.getId());
    controllerMap.put(index, controller);
    synchronized (eventQueue) {
        GwtControllerEvent event = eventPool.obtain();
        event.type = GwtControllerEvent.CONNECTED;
        event.controller = controller;
        eventQueue.add(event);
    }
}
Also used : Gamepad(com.badlogic.gdx.controllers.gwt.support.Gamepad)

Aggregations

Gamepad (com.badlogic.gdx.controllers.gwt.support.Gamepad)2 JsArrayNumber (com.google.gwt.core.client.JsArrayNumber)1