关于cocos2dx 2.x版本的各个layer和btn的touch关系的理解

来源:互联网 发布:外国搜图软件 编辑:程序博客网 时间:2024/04/28 11:55

第一篇放点水


虽然父子的node的遮挡是有关系的,但是各个node的touch是没有关联的,区别他们的是 touch priority --- 响应优先级,


比如一个 btn点击没响应 ,那么有两个原因,一是btn的selector没绑定,二是btn上有一层透明的node遮住了这个btn,因为这个node吃掉了(swallow)这个btn的touch


解决方法是:1.btn->setTouchEnabled(false);  // 里面做的事是移除touch代理


2.btn->setTouchPriority(); // 在此这是优先级, 越小的优先级越高,


3.btn->setTouchPriority(true);



同样的对于layer设置优先级:


CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this,InputManager::TUTORIAL_MASK_TOUCH_PRIORITY,true); 

//第二个参数是优先级,第三个参数是是否swallowtouch(吃掉响应),为true,就不传递touch给其他node,(不传给优先级更低的node)

0 0