CCObject *HTouchEnabledLayerColor::updatePriorityEx(int command, CCNode *node) { int iBasePriority = getTouchPriority(); if (dynamic_cast<CCControl *>(node)) { CCControl *control = (CCControl *)node; int priority = control->getTouchPriority(); priority = iBasePriority - 9; control->setTouchPriority(priority); if (control->isTouchEnabled()) { control->setTouchEnabled(false); control->setTouchEnabled(true); } } else if (dynamic_cast<CCScrollView *>(node)) { CCScrollView *scrollView = (CCScrollView *)node; int priority = scrollView->getTouchPriority(); priority = iBasePriority - 11; scrollView->setTouchPriority(priority); if (scrollView->isTouchEnabled()) { scrollView->setTouchEnabled(false); scrollView->setTouchEnabled(true); } } else if (dynamic_cast<CCMenu *>(node)) { CCMenu *menu = (CCMenu *)node; int priority = menu->getTouchPriority(); priority = iBasePriority - 128; menu->setTouchPriority(priority); if (menu->isTouchEnabled()) { menu->setTouchEnabled(false); menu->setTouchEnabled(true); } } else if (dynamic_cast<CCLayer *>(node)) { CCLayer *layer = (CCLayer *)node; int priority = layer->getTouchPriority(); priority = iBasePriority; layer->setTouchPriority(priority); if (layer->isTouchEnabled()) { layer->setTouchEnabled(false); layer->setTouchEnabled(true); } } CCArray *children = node->getChildren(); if (children) { int count = children->count(); for (int i = 0; i < count; ++i) { CCNode *child = (CCNode *)children->objectAtIndex(i); updatePriorityEx(command, child); } } return NULL; }
void CCtrlPage::onEnter( void ) { CCLayer::onEnter(); CCDirector* pDirector = CCDirector::sharedDirector(); if (NULL == pDirector) { return; } // 强行修改ScrollView的touch Priority=CtrlPage,后加入的CtrlPage会先响应才能吃掉TouchEnd CCTouchDispatcher* pDispatcher = CCDirector::sharedDirector()->getTouchDispatcher(); if (m_pScrollView && pDispatcher) { // 系统bug,setPriority不会寻找等待加入的Touch Handle // pDispatcher->setPriority(getTouchPriority(), m_pScrollView); pDispatcher->removeDelegate(m_pScrollView); pDispatcher->addTargetedDelegate(m_pScrollView, getTouchPriority(), false); } pDispatcher->removeDelegate(this); pDispatcher->addTargetedDelegate(this, getTouchPriority(), false); }
void GameLoadingLayer::registerWithTouchDispatcher() { CCLayer::registerWithTouchDispatcher(); CCObject* child; //循环获取父节点中的子节点 CCARRAY_FOREACH(m_pChildren, child) { CCLayer* pNode = dynamic_cast<CCLayer*>(child); if(pNode) { //设置子节点消息响应的优先级 pNode->setTouchPriority(getTouchPriority() + pNode->getTouchPriority()); } }
//Menu - Events void CCControl::registerWithTouchDispatcher() { CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, getTouchPriority(), true); }
//Menu - Events void Control::registerWithTouchDispatcher() { Director::getInstance()->getTouchDispatcher()->addTargetedDelegate(this, getTouchPriority(), true); }
void GiftListView::registerWithTouchDispatcher() { CCDirector* pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->addTargetedDelegate(this, getTouchPriority(), true); }
void OBScrollView::registerWithTouchDispatcher() { CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, getTouchPriority(), false); }