bool TouchEventTest::init() { bool bRef = false; do { CC_BREAK_IF(!CCLayer::init()); // 启用触摸 setTouchEnabled(true); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCPoint center = ccp(winSize.width/ 2, winSize.height / 2); // 创建可触摸精灵 LsTouch* lt = LsTouch::create(); // 设置位置 lt->setPosition(center); // 设置显示精灵 lt->setDisplay(CCSprite::create("Peas.png")); // 添加到显示 this->addChild(lt); // 添加到触摸管理,第二个参数,事件 Id this->addLsTouch(lt, 100); LsTouch* lt2 = LsTouch::create(); lt2->setPosition(ccpAdd(center, ccp(20, 10))); lt2->setDisplay(CCSprite::create("Peas.png")); addChild(lt2); this->addLsTouch(lt2, 101); bRef = true; } while (0); return bRef; }
bool LsTouchEvent::sendTouchMessage(CCTouch* ccTouch, int type) { // 编写判断,集合中的哪个元素级别高,就触发哪一个 LsTouch* lsTouch = NULL; // 获得点击的点 CCObject* pObj = NULL; LsTouch* lt = NULL; CCARRAY_FOREACH(m_pLsTouches, pObj) { lt = dynamic_cast<LsTouch*>(pObj); if (lt) { if (lt->selfCheck(ccTouch, this)) { if (lsTouch == NULL) lsTouch = lt; else // 如果已存在符合条件元素,比较优先级 lsTouch = this->getPriorityTouch(lsTouch, lt); } } }
bool LsTouchEvent::sendTouchMessage(CCTouch* ccTouch, int type) { LsTouch* lsTouch = NULL; CCObject* pObj = NULL; LsTouch* lt = NULL; CCARRAY_FOREACH(m_pLsTouches, pObj) { lt = dynamic_cast<LsTouch*>(pObj); if (lt) { if (lt->selfCheck(ccTouch, this)) { if (lsTouch == NULL) { lsTouch = lt; } else { lsTouch = getPriorityTouch(lsTouch, lt); } } } }