在libgdx中检测矩形上的多点触控

时间:2013-06-03 07:58:16

标签: java android libgdx

我有两个矩形A和B.我要做的是,当我按下第一个矩形(A)时,我的第二个矩形(B)将无法点击3秒钟,反之亦然。此外,如果按下任何矩形,则只有在用户触摸屏幕时才能点击另一个矩形。 即,只需轻轻一按,两个矩形都不应该点击。

我的做法如下:

boolean leftleftRectBool = false,rightRectBool = false;
long scanningTime =  System.currentTimeMillis()+3000;//in constructor

camera.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
    if(Gdx.input.isTouched())
    {
        if (leftThumbRectangle.contains(touchPoint.x, touchPoint.y)) {
                    if (scanningTime > System.currentTimeMillis()) {
                leftRectBool = false;
                scanningTimeStart = true;
            } else {
                scanningTime = 0;
                scanningTimeStart = false;
                leftRectBool = true;
                   }

             }
if(rightThumbRectangle.contains(touchPoint.x, touchPoint.y)) {
                       if (scanningTime > System.currentTimeMillis()) {
                rightRectBool = false;
                scanningTimeStart = true;
            } else {
                scanningTime = 0;
                scanningTimeStart = false;
                rightRectBool = true;
                   }
}

else {

        scanningTime = System.currentTimeMillis() + 3000;
     }
           if(lefttRectBool && lefttRectBool)
             {
              // some thing happen
             }

并在draw()

if(lefttRectBool)
{
//some thing haapens
}
else if(rightRectBool)
{
//some things happen
}

1 个答案:

答案 0 :(得分:0)

为扫描时间取两个变量,即两个矩形。

    boolean leftleftRectBool = false,rightRectBool = false;
long scanningTimeRight =  System.currentTimeMillis()+3000;
long scanningTimeLeft =  System.currentTimeMillis()+3000;

camera.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
    if(Gdx.input.isTouched())
    {
        if (leftThumbRectangle.contains(touchPoint.x, touchPoint.y)) {
                    if (scanningTime > System.currentTimeMillis()) {
                leftRectBool = false;
                scanningTimeStart = true;
            } else {
                scanningTimeRight = System.currentTimeMillis()+3000;
                scanningTimeStart = false;
                leftRectBool = true;
                   }

             }
if(rightThumbRectangle.contains(touchPoint.x, touchPoint.y)) {
                       if (scanningTime > System.currentTimeMillis()) {
                rightRectBool = false;
                scanningTimeStart = true;
            } else {
                scanningTimeLeft = System.currentTimeMillis()+3000;
                scanningTimeStart = false;
                rightRectBool = true;
                   }
}

else {

        scanningTimeRight = System.currentTimeMillis() + 3000;
        scanningTimeLeft = System.currentTimeMillis()+3000;
     }
           if(lefttRectBool && lefttRectBool)
             {
              // some thing happen
             }

试试这个。这可能有用。