3.2 multi toch not enabled in iOS

Hey, guys
It seems that the C++ template is missing setMultipleTouchEnabled for the eaglView in AppController.mm so the multi-touches does not work for iOS when I create new project with cocos-console.

setMultipleTouchEnabled is gone, depreciated, you don’t need it anymore.

To setup multitouch, init your listener like this, in your CPP/H layer files:-

// In your header file:
virtual bool onTouchesBegan(Touch* touch, Event* event);
virtual void onTouchesMoved(Touch* touch, Event* event);
virtual void onTouchesEnded(Touch* touch, Event* event);
EventListenerTouchAllAtOnce *m_pListener;

// In your CPP files Init:
m_pListener = EventListenerTouchAllAtOnce::create();
m_pListener->onTouchesBegan = CC_CALLBACK_2(HelloWorld::onTouchesBegan, this);
m_pListener->onTouchesMoved = CC_CALLBACK_2(HelloWorld::onTouchesMoved, this);
m_pListener->onTouchesEnded = CC_CALLBACK_2(HelloWorld::onTouchesEnded, this);
Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(m_pListener, -10);

// In your CPP files destructor:
Director::getInstance()->getEventDispatcher()->removeEventListener(m_pListener);

And you’ll get your "onTouches"Began/Moved/Ended to the new handlers, code to read multiple touches in a loop:

void HelloWorld::onTouchesBegan(const vector &touches, Event *event)
{
    Touch* touch;
    gdata.m_iTouchFingersOnScreen += touches.size();
    for( int iTouchCount = 0; iTouchCount < touches.size(); iTouchCount++ )     
    {         
        touch = touches.at(iTouchCount); 
        Point touchPoint = touch->getLocationInView();
        Point touchPointScreen = Director::getInstance()->convertToGL(location);
        .... act on the input ....
    }
1 Like

Sorry my question wasn’t clear enough. I am setting the listener on the event dispatcher. The setMultipleTouchEnabled I’m referring to is in the iOS specific files only and needs to be set to the eaglView itself in order for Cocos to receive them.

It’s missing in the template file, so multi-touch will not work for ios only.

Anyway, I’ve created a pull request for this hopefully it should be merged.

Cocos2d-x 3.5 is awesome! But why not make it better by enabling iOS Multi-Tocuh by default :wink:

Is there a reason why multi-touch is not enabled by default on iOS?
Is there any benefit to having it disabled by default on iOS?
I think it is already enabled by default on WP8 and Android.

Doesn’t it make sense to enable it by default, especially since enabling it requires the modification of cocos2d-x source code.

If not enabled by default, there should a least be a cocos2d-x api to enable/disable multi-touch on iOS, rather than requiring hacking the CCGLViewImpl-ios.mm file.

A related issue that might be a bug…
In the CCGLViewImpl-ios.mm file there are three methods to create the GLView.
It seems these three methods should either all enable multi-touch by default or all not enable it, rather than one enable it and two do not.

e.g.

  1. Multi-touch is enabled if the initWithRect method is used. That method contains the code [eaglview setMultipleTouchEnabled:YES];

  2. But currently, multi-touch is disabled if initWithEAGLView is used. This is the default init method for iOS.

  3. Multi-touch is disabled if initWithFullScreen is used in CCGLViewImpl-ios.mm.

Doesn’t anyone think that it would be better NOT to have to hack the cocos2d-x source code to enable multi-touch on iOS?

On iOS, it should be either enabled by default or an API in cocos2d-x should exist to enable/disable it.

I don’t understand why multi-touch should be enabled by default on WP8 and Android, but disabled by default on iOS.

for multi-touch? Can’t you just edit AppController.mm and add:

[eaglView setMultipleTouchEnabled:YES];
1 Like

Ah, that is much better than digging in the depths of cocos2d-x source to enable it. Thanks Slackmoehrle.

I still don’t understand why the cocos2d-x default setting for multi-touch is not consistent between Android, iOS and WP8. Why should the cocos2d-x API let it be disabled by default on iOS when it is enabled by default on WP8 and Android? That inconsistency can be frustrating to new users of the API.

I opened an issue for this in github as a feature enhancement but it was closed to instead be discussed here.
Maybe it is not a big enough issue for anyone to care :smile:

Don’t take the fact it was closed as not important. I submit things and they get closed but I know that they are still passed along for testing, evaluation, etc.

As of cocos2dx 3.14 you should be able to find this line in the RootViewController.mm in the loadView method [eaglView setMultipleTouchEnabled:NO];. By default it is set to NO cause all the best games use single touch. :unamused:

4 Likes