cocos2dx吧 关注:11,012贴子:33,717
  • 3回复贴,共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上面点击无效果 求解 求解


IP属地:江苏1楼2018-01-06 22:32回复
    不是用touchmove移动吗,我是新手


    IP属地:广东2楼2018-01-07 08:19
    收起回复