CCMenuItem* MyMenu::itemForTouch(CCTouch *touch) { CCPoint touchLocation = touch->getLocationInView(); touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation); if (m_pChildren && m_pChildren->count() > 0) { CCObject* pObject = NULL; CCARRAY_FOREACH(m_pChildren, pObject) { CCMenuItem* pChild = dynamic_cast<CCMenuItem*>(pObject); if (pChild && pChild->isVisible() && ((CCMenuItem*)pChild)->isEnabled()) { if (dynamic_cast<MyTiledMenuItemSprite*>(pChild) != NULL){ CCPoint posiT = map->transMapToTiled(this->getPosition()); CCPoint tiled = map->transMapToTiled(map->convertToNodeSpace(touchLocation)); if (contentSizeByTiled.width == 1 && contentSizeByTiled.height == 1) { CCPoint local = pChild->convertToNodeSpace(touchLocation); CCRect r = ((CCMenuItem*)pChild)->rect(); r.origin = CCPointZero; if (r.containsPoint(local)) { //物体碰撞系统参数,上面是地形碰撞系统 // ((MyMap*)map)->initTip(this->getPosition(), contentSizeByTiled.width); // ((MyMap*)map)->cancelAllBuilding(); // ((MyMap*)map)->moveTemp = this; cacheLoc = this->getPosition(); return (CCMenuItem*)pChild; } } else { if(Mathlib::inBound(tiled.x, posiT.x+contentSizeByTiled.width/2, posiT.x-contentSizeByTiled.width/2) && Mathlib::inBound(tiled.y, posiT.y+contentSizeByTiled.height/2, posiT.y-contentSizeByTiled.height/2)) { cacheLoc = this->getPosition(); // ((MyMap*)map)->initTip(this->getPosition(), contentSizeByTiled.width); // ((MyMap*)map)->cancelAllBuilding(); // ((MyMap*)map)->moveTemp = this; return (CCMenuItem*)pChild; } } } else { CCPoint local = pChild->convertToNodeSpace(touchLocation); CCRect r = ((CCMenuItem*)pChild)->rect(); r.origin = CCPointZero; if (r.containsPoint(local)) { //物体碰撞系统参数,上面是地形碰撞系统 //TODO // ((MyMap*)map)->moveTemp = this; cacheLoc = this->getPosition(); return (CCMenuItem*)pChild; } } } }
CCMenuItem* CPullMachMenu::itemForTouchPM(CCTouch * touch) { CCPoint touchLocation = touch->getLocation(); if (m_pChildren && m_pChildren->count() > 0) { CCObject* pObject = NULL; CCARRAY_FOREACH(m_pChildren, pObject) { CCMenuItem* pChild = dynamic_cast<CCMenuItem*>(pObject); if (pChild && pChild->isVisible() && pChild->isEnabled()) { CCPoint local = pChild->convertToNodeSpace(touchLocation); CCRect r; r.size = pChild->getContentSize(); r.origin.x = r.size.width * 0.2f; r.size.width *= 0.6f; r.origin.y = r.size.height * 0.2f; r.size.height *= 0.8f; if (r.containsPoint(local)) { return pChild; } } }
CCMenuItem* NewMenuDevice::itemForTouch(CCTouch *touch) { CCPoint touchLocation = touch->getLocationInView(); touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation); if (m_pChildren && m_pChildren->count() > 0) { CCObject* pObject = NULL; CCARRAY_FOREACH(m_pChildren, pObject) { CCMenuItem* pChild = dynamic_cast<CCMenuItem*>(pObject); if (pChild && pChild->isVisible() && ((CCMenuItem*)pChild)->isEnabled()) { if (dynamic_cast<NewMenuSpriteItem*>(pChild) != NULL){ CCPoint posiT = parent->getMap()->transMapToTiled(this->getPosition()); CCPoint tiled = parent->getMap()->transMapToTiled(parent->getMap()->convertToNodeSpace(touchLocation)); // CCLog("posiTx:%f,posiTy:%f", posiT.x,posiT.y); // CCLog("tiledX:%f,tiledY:%f", tiled.x,tiled.y); // CCLog("pChildTiledSizeW:%f,pChildTiledSizeH:%f",pChildTiledSize.width,pChildTiledSize.height); if(Mathlib::inBound(tiled.x, posiT.x+contentSizeByTiled.width/2, posiT.x-contentSizeByTiled.width/2) && Mathlib::inBound(tiled.y, posiT.y+contentSizeByTiled.height/2, posiT.y-contentSizeByTiled.height/2)) { isMoved = true; cacheLoc = this->getPosition(); ((NewCreateMap*)parent->getMap())->initTip(this->getPosition(), contentSizeByTiled.width); ((NewCreateMap*)parent->getMap())->moveTemp = this; ((NewCreateMap*)parent->getMap())->cancelAllBuilding(); return (CCMenuItem*)pChild; } } else { CCPoint local = pChild->convertToNodeSpace(touchLocation); CCRect r = ((CCMenuItem*)pChild)->rect(); r.origin = CCPointZero; if (r.containsPoint(local)) { return (CCMenuItem*)pChild; } } } }