如何在Android上进行多点触控?

时间:2014-07-26 18:01:53

标签: multithreading touch

我使用的是java,libgdx,box2d。

如何进行多点触控?这是我到目前为止所拥有的。单点触控可以正常工作。我需要改变它,以便它可以处理多点触控。

如果用户触摸屏幕的左侧比做某些事情。如果用户触摸屏幕右侧比做其他事情。

问题是,如果用户同时触摸屏幕的左侧和右侧,那么它只会做一件事。

我想改变它,如果用户同时触摸屏幕的左侧和右侧,那么它会做两件不同的事情。

 if (GameKeys.isPressed()) {
            if (GameKeys.x < Gdx.graphics.getWidth() / 2) {
           //touch left side of screen and do some thing
     }
}

if (GameKeys.isPressed()) {
        if (GameKeys.x > Gdx.graphics.getWidth() / 2) {
         //touch right side of screen and do some thing      
       }
 }

// gameinputprocessor class

public class GameInputProcessor extends InputAdapter {

    public boolean mouseMoved(int x, int y) {
        GameKeys.x = x;
        GameKeys.y = y;
        return true;
    }

    public boolean touchDragged(int x, int y, int pointer) {
        GameKeys.x = x;
        GameKeys.y = y;
        GameKeys.down = true;
        return true;
    }

    public boolean touchDown(int x, int y, int pointer, int button) {
        GameKeys.x = x;
        GameKeys.y = y;
        GameKeys.down = true;
        return true;
    }

    public boolean touchUp(int x, int y, int pointer, int button) {
        GameKeys.x = x;
        GameKeys.y = y;
        GameKeys.down = false;
        return true;
    }
}

// gamekeys class

public class GameKeys {
    public static int x;
    public static int y;
    public static boolean down;
    public static boolean pdown;

    public static boolean isDown() {
        return down;
    }

    public static boolean isPressed() {
        return down && !pdown;
    }

    public static boolean isReleased() {
        return !down && pdown;
    }
}

0 个答案:

没有答案