在多个layer的情况下,为了避免触摸事件穿透,我们要把触摸事件截取在当前层,具体做法如下
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(MyLayer::onTouchBegan, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
bool MyLayer::onTouchBegan(Touch *pTouch, Event *pEvent)
{
return true;
}
原文地址:http://www.cnblogs.com/niwococo/p/3955805.html