cocos2d吧 关注:2,599贴子:5,364
  • 0回复贴,共1

cocos2dx 3.x版本无法监听到menu的触摸

取消只看楼主收藏回复

在一个图层里面添加了一个Menu, 但是不想直接用回调函数,因为想通过触摸滑动实现特殊效果
所以init 函数后
setTouchEnabled(true);
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = [&](Touch* touch, Event *event) {
bool bIsTouched= m_pNodeSureBtn->onTouchBegan(touch, event);
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
bIsTouched 永远是flase,难道menu不能响应触摸事件吗>>>
然后使用
setTouchEnabled(true);
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = [&](Touch* touch, Event *event) {
bool bIsTouched= m_pNodeSureBtn->getBoundBox().containsPoint(touch->getLocation());
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
这样稍微偏移menu一点的地方触摸就会响应,但是在menu上面点击无效果 求解 求解


1楼2018-01-06 22:34回复