コード例 #1
0
  public GwtController(int index, String name) {
    this.index = index;
    this.name = name;

    Gamepad gamepad = Gamepad.getGamepad(index);
    axes = new float[gamepad.getAxes().length()];
  }
コード例 #2
0
ファイル: GwtControllers.java プロジェクト: libgdx/libgdx
 @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);
   }
 }
コード例 #3
0
ファイル: GwtControllers.java プロジェクト: libgdx/libgdx
  @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);
          }
        }
      }
    }
  }