-1

我有两个矩形 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
}
4

1 回答 1

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
             }

尝试这个。这可能有效。

于 2013-06-05T11:39:44.240 回答