How to disable MultiTouch in Cocos2d-x (Android)

Aleksei Pinchuk
Sep 10, 2018 · 2 min read

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.

HackerNoon.com

#BlackLivesMatter

Sign up for Get Better Tech Emails via HackerNoon.com

By HackerNoon.com

how hackers start their afternoons. the real shit is on hackernoon.com. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Aleksei Pinchuk

Written by

http://pinchuka.com/

HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store