Question

I am using Marmalade to create a project using Cocos2d-X, however I am not being able to use Multitouch in my project. The idea would be to identify pinch gestures to zoom in and out.

I've enabled touches in my GameLayer.cpp file using:

this->setTouchMode(kCCTouchesAllAtOnce);
this->setTouchEnabled(true);

I've also added the configuration below to my application's ICF file:

[S3E]
AndroidPointMultiEnable = 1

I have tested my application both on the simulator (enabling multitouch there) and in an Android tablet, but in the simulator the touches are not enven registed by my application and on the Android tablet I am receiving each touch as a separate event and not both at the same time.

Could you help me?

Thanks

UPDATE

Here is my code for ccTouchesBegan:

void GameLayer::ccTouchesBegan(CCSet* pTouches, CCEvent* event)
{
    CCSetIterator it;
    CCTouch *touch;
    CCPoint touchA;
    CCPoint touchB;

    IwTrace(APPLICATION, ("Touches Began - touch count: %d", pTouches->count()));

    it = pTouches->begin();

    if (usePinchGesture && pTouches->count() == 2)
    {
        touch = (CCTouch*) (*it);
        touchA = touch->getLocation();

        it++;

        touch = (CCTouch*) (*it);
        touchB = touch->getLocation();

        pinchDistance = GeomHelper::getDistanceSq(touchA, touchB);

        IwTrace(APPLICATION, ("Pinch gesture detected. Starting distance between points: %f", pinchDistance));
    }
}

The problem is that the count of touches pTouches->count() is always 1, so each touch event gets treated separately.

Thanks

Was it helpful?

Solution

Yep, pTouches->count() is always 1 in android!

cocos2d-x v2.2.3 in ..\cocos2dx\platform\android\jni\TouchesJni.cpp

blablabla...

JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeTouchesBegin(JNIEnv * env, jobject thiz, jint id, jfloat x, jfloat y) {
    cocos2d::CCDirector::sharedDirector()->getOpenGLView()->handleTouchesBegin(1, &id, &x, &y);
}

It's always 1 in the first param.

OTHER TIPS

On android, the multi-touch is open by default. You don’t need to open anything before get the touch coordinates in void MyLayer::ccTouchesBegan/Moved/Ended

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top