There was one problem in Cocos2d-x (before version 3.14). If you wanted to use single touch in Android you must comment the code into Cocos2d-x. But when you will replace Cocos2d-x with the new version, you must remember to comment the code again. This article will answer to how disabled multitouch for all version of Cocos2d-x without commenting the code.
How to disable multitouch by commenting the code discussed here.
It is logical to assume that in order to solve this problem it is necessary to remove all touches with id greater than 0. How it to do?
In Android all touches go through Cocos2dxGLSurfaceView. Let’s consider the case with action touch down.
We need to use the touch with idDown == 0 only. But there is one problem. mCocos2dxRenderer is a private member and when we inherit Cocos2dxGLSurfaceView, we can’t use mCocos2dxRenderer.
Let’s consider Cocos2dxRender methods handleActionDown, handleActionMove, handleActionUp and handleActionCancel.
This methods use static methods of Cocos2dxRender:
Fortunately, we use Java. In Java we can get access to private method. Let’s write the method for access to private method.
Now we should inherit Cocos2dxGLSurfaceView, use static methods of Cocos2dxRender and cut touches. Full code of MyCocos2dxGLSurfaceView:
And we should change method onCreateView in AppActivity.java
After discussing this problem, Cocos2d-x developers added a method setMultipleTouchEnabled in Cocos2dxGLSurfaceView in version ≥3.14. And now the single touch is done like this:
Ok. We have a single touch for different versions of the Cocos2d-x.
Create your free account to unlock your custom reading experience.