Q:

Touches outside a Node object also responded touch event

In my code, I add two sprites which type is .png with size 110*150. Two touch listeners are dispatched to each sprite. Somehow, no matter where I touched, listerner2 and listener will respond even if I touched out of the sprite, and the code will print listener2listener1 no matter where I touched, what's the problem with my code?
Scene* DemoScene::create()
{
    auto demoScene = Scene::create();

    if (demoScene == NULL) {
        return NULL;
    }

    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    auto demoSprite = Sprite::create("1.png");
    demoSprite->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height/2));
    demoScene->addChild(demoSprite);

    auto demoSprite2 = Sprite::create("1.png");
    demoSprite2->setPosition(Vec2(origin.x + visibleSize.width/3, origin.y + visibleSize.height/3));
    demoScene->addChild(demoSprite2);

    auto listener = EventListenerTouchOneByOne::create();
//    listener->setSwallowTouches(true);
    listener->onTouchBegan = [](Touch *touch, Event *event){
        printf("listener1");
        return true;
    };

    auto listener2 = EventListenerTouchOneByOne::create();
//    listener2->setSwallowTouches(true);
    listener2->onTouchBegan = [](Touch *touch, Event *event){
        printf("listener2");
        return true;
    };

    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, demoSprite);
    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener2, demoSprite2);

    return demoScene;

}

A:

Event listener does not check if the tap is inside the Sprite or not. You should control it manually. If the demoSprite is touched, returning true on onTouchBegan method will prevent propagating the touch to the other listeners. (if swallow touches is set to true) 
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = [](Touch *touch, Event *event){

    // check if the touch is inside the target
    Vec2 locationInNode = event->getCurrentTarget()->convertToNodeSpace(touch->getLocation());
    Size s = event->getCurrentTarget()->getContentSize();
    Rect rect = Rect(0,0, s.width, s.height);

    if (rect.containsPoint(locationInNode)) {
        printf("listener1");
        return true;
    }

    return false;
};

auto listener2 = EventListenerTouchOneByOne::create();
listener2->setSwallowTouches(true);
listener2->onTouchBegan = [](Touch *touch, Event *event){

    // check if the touch is inside the target
    Vec2 locationInNode = event->getCurrentTarget()->convertToNodeSpace(touch->getLocation());
    Size s = event->getCurrentTarget()->getContentSize();
    Rect rect = Rect(0,0, s.width, s.height);

    if (rect.containsPoint(locationInNode)) {
        printf("listener2");
        return true;
    }

    return false;
};

