public boolean onTouch(View v, MotionEvent event) {
    boolean result = false;

    for (int i = 0; i < buttons.length; ++i) {
      if (buttons[i].processTouch(v, event)) {
        result = true;
        break;
      }
    }

    if (result != true) {
      gestureDetector.onTouchEvent(event);

      for (int i = 0; i < joysticks.length; ++i) {
        JoystickBase joy = joysticks[i];
        if (joy != null) {
          if (joy.processTouch(v, event)) {

            result = true;
          }
        }
      }
    }

    //		if (event.getAction() == MotionEvent.ACTION_MOVE) {
    //		    // Trying to avoid flooding of ACTION_MOVE events
    //			try {
    //				Thread.sleep(33);
    //			} catch (InterruptedException e) {
    //				e.printStackTrace();
    //			}
    //		}

    return result;
  }
  public void setJoysticks(JoystickBase left, JoystickBase right) {
    joysticks[0] = left;
    if (left != null) {
      joysticks[0].setAlign(Align.BOTTOM_LEFT);
      joysticks[0].setAlpha(joypadOpacity);
    }
    joysticks[1] = right;
    if (right != null) {
      joysticks[1].setAlign(Align.BOTTOM_RIGHT);
      joysticks[1].setAlpha(joypadOpacity);
    }

    for (int i = 0; i < joysticks.length; ++i) {
      JoystickBase joystick = joysticks[i];

      if (joystick != null) {
        if (!useSoftwareRendering) {
          joystick.setInverseYWhenDraw(true);
        } else {
          joystick.setInverseYWhenDraw(false);
        }

        int margin = context.getResources().getDimensionPixelSize(R.dimen.hud_joy_margin);

        joystick.setMargin(0, margin, bottomBarBg.getHeight() + margin, margin);
      }
    }

    renderer.removeSprite(JOY_ID_LEFT);
    renderer.removeSprite(JOY_ID_RIGHT);

    if (left != null) {
      renderer.addSprite(JOY_ID_LEFT, left);
    }

    if (right != null) {
      renderer.addSprite(JOY_ID_RIGHT, right);
    }
  }