在android平台上, 点击指定位置的一个按钮,log cat提示:if the index doesn’t exist, it is an error
我已经在org.cocos2dx.lib.Cocos2dxGLSurfaceView.java里面的函数中屏蔽多点触摸:
public boolean onTouchEvent(final MotionEvent pMotionEvent) {
// these data are used in ACTION_MOVE and ACTION_CANCEL
final int pointerNumber = pMotionEvent.getPointerCount();
final int] ids = new int;
final float] xs = new float;
final float] ys = new float;
for (int i = 0; i < pointerNumber; i++) {
ids* = pMotionEvent.getPointerId(i);
xs* = pMotionEvent.getX(i);
ys* = pMotionEvent.getY(i);
}
switch (pMotionEvent.getAction() & MotionEvent.ACTION_MASK) {
//2015-7-9 zhangbao 去掉多点触摸功能
// case MotionEvent.ACTION_POINTER_DOWN:
// final int indexPointerDown = pMotionEvent.getAction() >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
// final int idPointerDown = pMotionEvent.getPointerId(indexPointerDown);
// final float xPointerDown = pMotionEvent.getX(indexPointerDown);
// final float yPointerDown = pMotionEvent.getY(indexPointerDown);
//
// this.queueEvent(new Runnable() {
// @Override
// public void run() {
// Cocos2dxGLSurfaceView.this.mCocos2dxRenderer.handleActionDown(idPointerDown, xPointerDown, yPointerDown);
// }
// });
// break;
case MotionEvent.ACTION_DOWN:
// there are only one finger on the screen
final int idDown = pMotionEvent.getPointerId(0);
final float xDown = xs;
final float yDown = ys;
this.queueEvent(new Runnable() {
@Override
public void run() {
Cocos2dxGLSurfaceView.this.mCocos2dxRenderer.handleActionDown(idDown, xDown, yDown);
}
});
break;
case MotionEvent.ACTION_MOVE:
this.queueEvent(new Runnable() {
@Override
public void run() {
Cocos2dxGLSurfaceView.this.mCocos2dxRenderer.handleActionMove(ids, xs, ys);
}
});
break;
//2015-7-9 zhangbao 去掉多点触摸功能
// case MotionEvent.ACTION_POINTER_UP:
// final int indexPointUp = pMotionEvent.getAction() >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
// final int idPointerUp = pMotionEvent.getPointerId(indexPointUp);
// final float xPointerUp = pMotionEvent.getX(indexPointUp);
// final float yPointerUp = pMotionEvent.getY(indexPointUp);
//
// this.queueEvent(new Runnable() {
// @Override
// public void run() {
// Cocos2dxGLSurfaceView.this.mCocos2dxRenderer.handleActionUp(idPointerUp, xPointerUp, yPointerUp);
// }
// });
// break;
case MotionEvent.ACTION_UP:
// there are only one finger on the screen
final int idUp = pMotionEvent.getPointerId(0);
final float xUp = xs;
final float yUp = ys;
this.queueEvent(new Runnable() {
@Override
public void run() {
Cocos2dxGLSurfaceView.this.mCocos2dxRenderer.handleActionUp(idUp, xUp, yUp);
}
});
break;
case MotionEvent.ACTION_CANCEL:
this.queueEvent(new Runnable() {
@Override
public void run() {
Cocos2dxGLSurfaceView.this.mCocos2dxRenderer.handleActionCancel(ids, xs, ys);
}
});
break;
}
/*
if (BuildConfig.DEBUG) {
Cocos2dxGLSurfaceView.dumpMotionEvent(pMotionEvent);
}
*/
return true;
}
```
***
echo "if the index doesn't exist, it is an error" ```