得到一些錯誤,不知道該怎麼做。請幫忙。嘗試在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;
}
}
你是什麼人在這裏嘗試achive touchEvent.x = touchX [pointerId] =(INT)(事件 .getX(pointerIndex)*的scaleX); ??? 它應該是這樣的 touchEvent.x = touchX [pointerId] =(int)(event .getX()* scaleX); –
我創建的TouchEvent實例池登記處理作爲OnTouchListener,並存儲滾動值 –