How to detect touch except the falling bodies from top in cocos2d-x ios game using c++

In my game there are certain zombies coming from top of the screen.I have stored all zombies sprites in an CCArray.Then using foreach loop I am making them falling down. I just want to perform combo.It means that whenever I kill a zombie on tap, the combo_counter increases. On killing two consecutive zombies the combo_counter goes to 2 but if I tap at any other location on the screen the combo_counter should go to 0.

So my problem is how to detect whether I have not tapped a zombie and tapped anyother place on the screen.I am attaching my code also of cctouchbegan method

zombies is a CCArray where all zombie sprites are stored

void Level1::ccTouchesBegan(cocos2d::CCSet *pTouch, cocos2d::CCEvent *pEvent)
{
 
CCTouch* touch = (CCTouch*)(pTouch->anyObject());
CCPoint location = touch->getLocationInView();
location = CCDirector::sharedDirector()->convertToGL(location);
 
CCObject* touchedzombie;
 
CCARRAY_FOREACH(zombies, touchedzombie)
{
 

    if(!((CCSprite*) touchedzombie)->isVisible())
        continue;
    //

    if(((CCSprite*)touchedzombie)==zombies->objectAtIndex(0))
    {
 
        //   if((CCSprite*(touchedzombie)==zombies-))
        if(touchedzombie!=NULL&&((CCSprite*)touchedzombie)->boundingBox().containsPoint(location))
        {
 
            this->setScoreonGame();
            combo_counter++;
            CCString *comboString=CCString::createWithFormat("comboX %d",combo_counter);
 
            zombies_left--;
            CCLOG("left = %d",zombies_left);
            CCSize tt=((CCSprite*)touchedzombie)->getContentSize();
            CCPoint pos_of_sprite=((CCSprite*)touchedzombie)->getPosition();
            int rand_die1=Level1::random1();
            CCString *str = CCString::createWithFormat("z2%d.png", rand_die1);
            changedSprite = CCSprite::create(str->getCString());
            CCLOG("Inside index 0");
 
            ((CCSprite*)touchedzombie)->setVisible(false);
 
            changedSprite->setPositionX(pos_of_sprite.x);
            changedSprite->setPositionY(pos_of_sprite.y);
            changedSprite->setScaleX(Utils::getScaleX());
            changedSprite->setScaleY(Utils::getScaleY());
            this->addChild(changedSprite);
 

            combo=CCLabelTTF::create(comboString->getCString(), "HoboStd", 50);
            combo->setColor(ccRED);
            combo->setPosition((ccp(changedSprite->getContentSize().width*0.50,changedSprite->getContentSize().height*1.05)));
            changedSprite->addChild(combo,40);
 

 
            this->runAction(CCSequence::create(delayAction,
                                               callSelectorAction,
                                               NULL));
 

            this->removeChild( ((CCSprite*)touchedzombie),true);
            this->Level1::reloadZombies();
            //  touchedzombie=NULL;

        }
 

 

 

    }
 

 

 
    if(((CCSprite*)touchedzombie)==zombies->objectAtIndex(3))
    {
 

        //   if((CCSprite*(touchedzombie)==zombies-))
        if(touchedzombie!=NULL&&((CCSprite*)touchedzombie)->boundingBox().containsPoint(location))
        {
         //    iftouched++;
            this->setScoreonGame();
            combo_counter++;
            CCString *comboString=CCString::createWithFormat("comboX %d",combo_counter);
 
            zombies_left--;
            CCLOG("left = %d",zombies_left);
            CCSize tt=((CCSprite*)touchedzombie)->getContentSize();
            CCPoint pos_of_sprite=((CCSprite*)touchedzombie)->getPosition();
            int rand_die1=Level1::random1();
            CCString *str = CCString::createWithFormat("z2%d.png", rand_die1);
            changedSprite3 = CCSprite::create(str->getCString());
            //  CCLOG("%s",str->getCString());

 
            //  CCLOG("Sprite Toucheddd");
            CCLOG("Inside index 4");
            // CCLog("width= %f  height =%f",tt.width,tt.height);
            // CCLog("x location =%f  y location =%f",location.x,location.y);
            //  CCLog("Positon of Sprite X=%f  Y=%f",pos_of_sprite.x,pos_of_sprite.y);

            ((CCSprite*)touchedzombie)->setVisible(false);
 
            changedSprite3->setPositionX(pos_of_sprite.x);
            changedSprite3->setPositionY(pos_of_sprite.y);
            changedSprite3->setScaleX(Utils::getScaleX());
            changedSprite3->setScaleY(Utils::getScaleY());
            this->addChild(changedSprite3);
 
            combo=CCLabelTTF::create(comboString->getCString(), "HoboStd", 50);
            combo->setColor(ccRED);
            combo->setPosition((ccp(changedSprite3->getContentSize().width*0.50,changedSprite3->getContentSize().height*1.05)));
            changedSprite3->addChild(combo,40);
 

            this->runAction(CCSequence::create(delayAction,
                                               callSelectorAction3,
                                               NULL));
 
            this->removeChild( ((CCSprite*)touchedzombie),true);
            this->Level1::reloadZombies();
            touchedzombie=NULL;
        }
        //..upto 9 indexes...      
    }
}


iterate through each zombie and check if any zombie was tapped .if no zombie is tapped then that tap was on the screen.

You can use bounding box, check to see if your touch has intercepted any of the zombie rects then if not set combo to zero.

Why not time your combo’s? that way you dnt need to check collision, they need to hit a zombie within couple of seconds to ++combo.

@kronicali i cant use time combo because in each level the speed of the zombies coming is different and it are increasing…i have done everything but still unable to fix the code for my problem

OK, just add else,

if(touchedzombie!=NULL&&((CCSprite*)touchedzombie)->boundingBox().containsPoint(location)) { }else combo_counter =0;