Hi!,
Is there anyway to disable multitouch in android? Can’t seem to find a way to do it checking the docs + sources.
Thanks in advance.
Hi!,
Is there anyway to disable multitouch in android? Can’t seem to find a way to do it checking the docs + sources.
Thanks in advance.
If you want disable multi touch on android you can edit Cocos2dxGLSurfaceView.java file
https://github.com/cocos2d/cocos2d-x/blob/master/cocos2dx/platform/android/java/src/org/cocos2dx/lib/Cocos2dxGLSurfaceView.java
and here is the code
int idTab[] = new int[1];
float xTab[] = new float[1];
float yTab[] = new float[1];
@Override
public boolean onTouchEvent(final MotionEvent pMotionEvent) {
// these data are used in ACTION_MOVE and ACTION_CANCEL
final int id = pMotionEvent.getPointerId(0);
final float xs = pMotionEvent.getX(0);
final float ys = pMotionEvent.getY(0);
final int event = pMotionEvent.getAction() & MotionEvent.ACTION_MASK;
if (event == MotionEvent.ACTION_DOWN
|| event == MotionEvent.ACTION_POINTER_DOWN) {
queueEvent(new Runnable() {
@Override
public void run() {
Cocos2dxRenderer.nativeTouchesBegin(id, xs, ys);
}
});
} else if (event == MotionEvent.ACTION_MOVE) {
idTab[0] = id;
xTab[0] = xs;
yTab[0] = ys;
queueEvent(new Runnable() {
@Override
public void run() {
Cocos2dxRenderer.nativeTouchesMove(idTab, xTab, yTab);
}
});
} else if (event == MotionEvent.ACTION_UP
|| event == MotionEvent.ACTION_POINTER_UP) {
queueEvent(new Runnable() {
@Override
public void run() {
Cocos2dxRenderer.nativeTouchesEnd(id, xs, ys);
}
});
} else if (event == MotionEvent.ACTION_CANCEL) {
idTab[0] = id;
xTab[0] = xs;
yTab[0] = ys;
queueEvent(new Runnable() {
@Override
public void run() {
Cocos2dxRenderer.nativeTouchesCancel(idTab, xTab, yTab);
}
});
}
return true;
}
Another way is just go to Cocos2dxGLSurfaceView.java file and go to onTouchEvent
Just comment the switch case case MotionEvent.ACTION_POINTER_DOWN:. No need to modify anything else. It worked for me.
// case MotionEvent.ACTION_POINTER_DOWN:
// final int indexPointerDown = pMotionEvent.getAction() >> MotionEvent.ACTION_POINTER_ID_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;
```
Cheers