Cocos2dx 创建屏蔽层 2.x

http://blog.csdn.net/z104207/article/details/19827453

 

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方法

 
posted @ 2014-03-18 17:13  六界剑仙  阅读(170)  评论(0)    收藏  举报