Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
There is one problem in Cocos2d-x. If you want 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. How to avoid this? This article will answer to this question.
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
Ok. We have single touch. Let me know how do you solve this problem?
How to disable MultiTouch in Cocos2d-x (Android) was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.