2012-01-24 217 views
1

我想弄清楚如何檢測手指從屏幕上擡起。 Essentialy我想我的程序執行的操作,一旦手指下降,直到同一個手指了一下我到目前爲止沒有檢測一次手指上升:觸摸後如何檢測觸摸

for(int i = 0; i < len; i++) { 
    TouchEvent event = touchEvents.get(i); 
    if(event.type == TouchEvent.TOUCH_DOWN) { 
     while (event.type != TouchEvent.TOUCH_UP){ 
      if((event.y > 160) && ((world.batMan.getY() + world.batMan.getLength()) < 319)) { 
       world.bat.moveSouth(); 
      } 
      if((event.y < 160) && (world.batMan.getY() > 0)) { 
       world.bat.moveNorth(); 
      } 
      event = touchEvents.get(i); 
     } 
    } 
} 

解決它雖然我覺得我現在已經使它比需要更復雜!

對(INT I = 0;我< LEN;我++){

 TouchEvent event = touchEvents.get(i); 



     if (event.type == TouchEvent.TOUCH_UP) 
     { 
      System.out.println("WOOT"); 
      touchNorth = false; 
      touchSouth = false; 
     } 

     else { 


      if((event.y > 160) && ((world.bat.getY() + world.bat.getLength()) < 319) 
        | (touchSouth == true)) { 
       touchSouth = true; 


      } 

      if((event.y < 160) && (world.bat.getY() > 0) | (touchNorth == true)) { 
       touchNorth = true; 

      } 

     } 
    } 


    if((touchSouth == true) && ((world.bat.getY() + world.bat.getLength()) < 319)) { 
     world.bat.moveSouth(); 
     touchSouth = true; 
    } 

    if(touchNorth == true && (world.bat.getY() > 0)) { 
     world.bat.moveNorth(); 
     touchNorth = true; 

    } 

回答

3

您有無限循環:

while (event.type != TouchEvent.TOUCH_UP){ 

... 

event = touchEvents.get(i); 
} 

i從不這個循環中遞增。我很驚訝你的應用沒有被系統關閉。