[LIBGDX] [Android]如果我在屏幕上按下2个手指,会出现错误?

时间:2015-09-11 22:38:17

标签: java android libgdx touch

我已经在LibGDX上开发了一款游戏并将其移植到了android上,所以我不得不在屏幕控制上制作但最近我发现(通过android开发工具)当我不断触摸按钮向左转并尝试跳它有时不会记录跳跃触摸。当两个触摸的Y坐标或多或​​少相同时,它不会记录。

-Sorry我无法解释它。

P.S。:手机是全新的,我的手指很干净,屏幕上有保护层,也很干净。

更新:我试图去除屏幕的保护层,它完美地工作。跳跃按钮附近可能有某种气泡。

以下是我的屏幕控制(以防万一):

    //BTW I use the camera to get a viewport of 1280x780 for all resolutions so I have to convert screen coordinates to world coordinates
    //Begin SpriteBatch
    sb.begin();

    sb.draw(websiteBanner, 0, 0, Camera.originalRes.x * Camera.cameraScale.x* Camera.resolutionRatio.x, Camera.androidControlsOffset* Camera.resolutionRatio.y);

    //On screen controls textures
    sb.draw(goLeftRightButton, 0, 0, controlsWidth* Camera.resolutionRatio.x, Camera.androidControlsOffset* Camera.resolutionRatio.y);
    sb.draw(duckButton, Gdx.graphics.getWidth() - (controlsWidth)*Camera.resolutionRatio.x, 0, controlsWidth / 2* Camera.resolutionRatio.x, Camera.androidControlsOffset* Camera.resolutionRatio.y);
    sb.draw(jumpButton, Gdx.graphics.getWidth() - (controlsWidth / 2)*Camera.resolutionRatio.x, 0, controlsWidth / 2* Camera.resolutionRatio.x, Camera.androidControlsOffset* Camera.resolutionRatio.y);

    sb.end();

    boolean goLeftTest = false;
    boolean goRightTest = false;
    boolean duckTest = false;
    boolean jumpTest = false;

    //maximum of 4 fingers at a time
    for(int i = 0; i < 4; i++) {
        if (Gdx.input.isTouched(i)) {
            //Utils.pointInsideBox uses the Rectangle class from badlogic and 
            //goLeft
            if (!goLeftTest && Utils.pointInsideBox(Gdx.input.getX(i) / Camera.resolutionRatio.x, (Gdx.graphics.getHeight() - Gdx.input.getY(i)) / Camera.resolutionRatio.y, 0, 0, controlsWidth / 2, Camera.androidControlsOffset)) {
                goLeftTest = true;
            }

            //goRight
            if (!goRightTest && Utils.pointInsideBox(Gdx.input.getX(i) / Camera.resolutionRatio.x, (Gdx.graphics.getHeight() - Gdx.input.getY(i)) / Camera.resolutionRatio.y, controlsWidth / 2, 0, controlsWidth / 2, Camera.androidControlsOffset)) {
                goRightTest = true;
            }

            //Duck
            if (!duckTest && Utils.pointInsideBox(Gdx.input.getX(i) / Camera.resolutionRatio.x, (Gdx.graphics.getHeight() - Gdx.input.getY(i)) / Camera.resolutionRatio.y, Camera.originalRes.x * Camera.cameraScale.x - controlsWidth, 0, controlsWidth / 2, Camera.androidControlsOffset)) {
                duckTest = true;
            }

            //Jump
            if (!jumpTest && Utils.pointInsideBox(Gdx.input.getX(i) / Camera.resolutionRatio.x, (Gdx.graphics.getHeight() - Gdx.input.getY(i)) / Camera.resolutionRatio.y, Camera.originalRes.x * Camera.cameraScale.x - controlsWidth / 2, 0, controlsWidth / 2, Camera.androidControlsOffset)) {
                jumpTest = true;
            }
        }
    }

    //Replace the booleans
    goLeft = goLeftTest;
    goRight = goRightTest;
    duck = duckTest;
    jump = jumpTest;

0 个答案:

没有答案