The layer does not response "ccTouchesBegan" after adding a layer on it and removed.

The layer does not response "ccTouchesBegan" after adding a layer on it and removed.
0.0 0


There are a layer which support mutiTouch. At first,it can response the mothed “ccTouchBegan” and then response “ccTouchesBegan”. Let’s call it “fatherLayer”.
When I add another layer “childLayer” on it and remove the “childLayer”, the fatherLayer is only response “ccTouchBegan” but never response “ccTouchesBegan”. I wonder why it is.

The “fatherLayer” like this:

bool fatherLayer::ccTouchBegan(CCTouch *touch,CCEvent *events)//This mothed can always be respond.
{   CCLog("=== ccTouchBegan  -- 1");
        return false; //If there is "return true", it will never response "ccTouchesBegan".

void fatherLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent){
      switch (pTouches->count()) {
            case 1: {           
            CCLog("=== ccTouchesBegan  case1 -- 1");
            } break;

            case 2: {
                        CCLog("=== ccTouchesBegan  case2 -- 1");
            } break;

The childLayer

bool childLayer::ccTouchBegan(cocos2d::CCTouch* touch, cocos2d::CCEvent* events){
    return true;

The two class both implement CCLayer.

Is someone know the reason? Thanks.


ccTouchBegan belongs to CCTargetedTouchDelegate, while ccTouchesBegan belongs to CCStandardTouchDelegate. They are invoked in the different phase of CCTouchDispatcher::touches(…) method. In theory, a CCLayer object can be a targeted delegate and a standard delegate concurrently.

Form your code above, I cannot adjudge the what’s the reason. The key must be where you add the touch delegates, and where you add/remove the child.
Can you modify HelloWorld and reproduce this problem? It will be much helpful for me to trace it. It may be an wrong usage, or may be a bug in engine.


I have found the reason. Not a bug in engine but an wrong usage.
My colleague used the wrong method “addTargetedDelegate” before adding the father layer. While replaced it with “addStandardDelegate”, the problem was solved.

As your reply reminded me, I checked and found it. Extremely grateful for you!