2013-06-03 182 views
-1

我有兩個矩形A和B.我必須做的是,當我的第一個矩形(A)被按下時,我的第二個矩形(B)將不能點擊3秒鐘, -versa。另外,如果任何矩形被按下,則只有當用戶觸摸屏幕時才能點擊另一個矩形。 即兩個長方形不應該點擊一次觸摸。檢測多邊形在矩形libgdx

我做如下:

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 
      } 

和平局()

if(lefttRectBool) 
{ 
//some thing haapens 
} 
else if(rightRectBool) 
{ 
//some things happen 
} 
+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 
      } 

試試這個。這可能工作。