前端之家收集整理的这篇文章主要介绍了
cocos2d-x 3.2 实现模态对话框,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用Layer实现对话框,在init函数中添加以下代码
auto listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [=](Touch *touch,Event *event)
{
return true;
};
listener->setSwallowTouches(true);
_eventDispatcher->addEventListenerWithSceneGraPHPriority(listener,this);
listener->setSwallowTouches(true);不向下传递触摸,比如有两个Layer A和B,A在B上面,触摸A时,事件就不会传递到B,从而实现模态对话框 listener->setSwallowTouches(false);向下传递触摸事件
原文链接:https://www.f2er.com/cocos2dx/347059.html