0

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

Felipe
  • 6,312
  • 11
  • 52
  • 70

2 Answers2

1

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.

Stefan van den Akker
  • 6,661
  • 7
  • 48
  • 63
young wong
  • 26
  • 3
0

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

Sumit Kandoi
  • 427
  • 4
  • 12
  • Hi, thanks for your answer. Currently I am getting the touches, but I am getting them one at the time, and not both touches at the same time (which was what I expected), I mean, the ccTouchesBegan gets called twice with one touch, instead of once with two or more touches. – Felipe May 12 '14 at 11:11