cocos2dx 创建屏蔽层

cocos2d 创建屏蔽层,修改优先级,禁止点击的事件向下传递!网上大部的资料都是 CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,-129,true);

为层添加一个addTargetedDelegate

当不使用这个层时还要在 onExit事件里删除掉。

光听起来就觉得麻烦。其实cocos2dx 里的层都有屏蔽功能 。只要修改一下属性就可以了。如下:

this->setTouchEnabled(true);
this->setTouchPriority(-129);
this->setTouchMode(kCCTouchesOneByOne);
this->registerWithTouchDispatcher();

这样这个层就可以禁止向下传事件了。当然 没有addTargetedDelegate ,也就不需要再去在onExit事件里删除了。

PS:记得重载ccTouchBegan方法