2012-07-04 24 views
0

得到一些錯誤,不知道該怎麼做。請幫忙。嘗試在Android 1.5版本中開發蛇遊戲並使用eclipse sdk 4.2.0版似乎這些錯誤是阻止我能夠調試我的遊戲的唯一因素。MultiTouchHandler幾個錯誤?

The method getX() in the type MotionEvent is not applicable for the arguments (int) 
The method getY() in the type MotionEvent is not applicable for the arguments (int) 
The method getX() in the type MotionEvent is not applicable for the arguments (int) 
The method getY() in the type MotionEvent is not applicable for the arguments (int) 
The method getPointerCount() is undefined for the type MotionEvent 
The method getPointerId(int) is undefined for the type MotionEvent 
ACTION_POINTER_DOWN cannot be resolved or is not a field  
The method getX() in the type MotionEvent is not applicable for the arguments (int) 
The method getY() in the type MotionEvent is not applicable for the arguments (int) 
ACTION_POINTER_UP cannot be resolved or is not a field MultiTouchHandler.java 
ACTION_MASK cannot be resolved or is not a field  
ACTION_POINTER_ID_MASK cannot be resolved or is not a field 
ACTION_POINTER_ID_SHIFT cannot be resolved or is not a field 
The method getPointerId(int) is undefined for the type MotionEvent 

代碼:

public boolean onTouch(View v, MotionEvent event) { 
    synchronized (this) { 
     int action = event.getAction() & MotionEvent.ACTION_MASK; 
     int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT; 
     int pointerId = event.getPointerId(pointerIndex); 

     switch (action) { 
     case MotionEvent.ACTION_DOWN: 
     case MotionEvent.ACTION_POINTER_DOWN: 
      touchEvent = touchEventPool.newObject(); 
      touchEvent.type = TouchEvent.TOUCH_DOWN; 
      touchEvent.pointer = pointerId; 
      touchEvent.x = touchX[pointerId] = (int) (event 
        .getX(pointerIndex) * scaleX); 
      touchEvent.y = touchY[pointerId] = (int) (event 
        .getY(pointerIndex) * scaleY); 
      isTouched[pointerId] = true; 
      touchEventsBuffer.add(touchEvent); 
      break; 

     case MotionEvent.ACTION_UP: 
     case MotionEvent.ACTION_POINTER_UP: 
     case MotionEvent.ACTION_CANCEL: 
      touchEvent = touchEventPool.newObject(); 
      touchEvent.type = TouchEvent.TOUCH_UP; 
      touchEvent.pointer = pointerId; 
      touchEvent.x = touchX[pointerId] = (int) (event 
        .getX(pointerIndex) * scaleX); 
      touchEvent.y = touchY[pointerId] = (int) (event 
        .getY(pointerIndex) * scaleY); 
      isTouched[pointerId] = false; 
      touchEventsBuffer.add(touchEvent); 
      break; 

     case MotionEvent.ACTION_MOVE: 
      int pointerCount = event.getPointerCount(); 
      for (int i = 0; i < pointerCount; i++) { 
       pointerIndex = i; 
       pointerId = event.getPointerId(pointerIndex); 

       touchEvent = touchEventPool.newObject(); 
       touchEvent.type = TouchEvent.TOUCH_DRAGGED; 
       touchEvent.pointer = pointerId; 
       touchEvent.x = touchX[pointerId] = (int) (event 
         .getX(pointerIndex) * scaleX); 
       touchEvent.y = touchY[pointerId] = (int) (event 
         .getY(pointerIndex) * scaleY); 
       touchEventsBuffer.add(touchEvent); 
      } 
      break; 
     } 

     return true; 
    } 
} 
+0

你是什麼人在這裏嘗試achive touchEvent.x = touchX [pointerId] =(INT)(事件 .getX(pointerIndex)*的scaleX); ??? 它應該是這樣的 touchEvent.x = touchX [pointerId] =(int)(event .getX()* scaleX); –

+0

我創建的TouchEvent實例池登記處理作爲OnTouchListener,並存儲滾動值 –

回答

0

所有這些mthods你得到錯誤的都不在你選擇的API級別可用。增加API級別或刪除任何多點觸控專用代碼。

+0

似乎解決我的問題謝謝 –

+0

很高興聽到這個:) – Magicode

0

你的方法/變量不匹配達到在其中您使用的是他們通過它的外觀的上下文所需要的類型。

看你的代碼,看看方法的參數和返回的所有比賽了。

+0

敢肯定,他們都投其所好 –