在多个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;
}
时间: 2024-10-10 01:35:53