////////////////////////////////////////////////////////////////////////// //called when touch layer ////////////////////////////////////////////////////////////////////////// void LevelLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) { CCTouch* touch = (CCTouch*)pTouches->anyObject(); CCPoint oldPT = touch->getLocationInView(); oldPT = CCDirector::sharedDirector()->convertToGL(oldPT); m_touchWinPoint = oldPT; float deviceScale = CCDirector::sharedDirector()->getContentScaleFactor(); oldPT = CCPoint(oldPT.x * deviceScale, oldPT.y * deviceScale); CCPoint newPT = LevelMultiResolution::sTransformWindowPointToMap(oldPT); // Note: 打断自动寻路到副本显示感叹号 TaskManager::getInstance()->InterruptAutoGoToInstanceEvent(); //by benyang: deal with npc first if(!NPCManager::sharedManager()->processTouch(newPT)) { //send touch begin event to children CCArray* children = this->getChildren(); if (children) { int childrenCount = children->count(); for (int i = 0; i < childrenCount; ++i) { CCNode* child = (CCNode* )children->objectAtIndex(i); ASSERT(child != NULL, "child is NULL"); BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag()); if (listener) { listener->HandleLayerTouchBeginEvent(child, newPT); } } } } //上面的listener未命中,直接调用SpriteSeerListener SpriteSeer * seer = GameManager::Get()->getHero(); if (seer) { BaseListener* listener = LevelLayer::sGetListenerByTag(seer->getTag()); if (listener) { listener->HandleLayerTouchBeginEvent(seer, newPT); } } //record touch point in map m_touchWinPoint = oldPT; }
////////////////////////////////////////////////////////////////////////// //update movable objects z order ////////////////////////////////////////////////////////////////////////// void LevelLayer::update(float dt) { //m_cameraController.Update(dt); CameraController::sharedCameraController()->Update(dt); for(std::map<unsigned int, WAKL_INFO>::iterator iter = m_walkInfo.begin(); iter != m_walkInfo.end(); iter++) { if(iter->second.idleTime.time <= iter->second.idleTime.curTime && !iter->second.walk.bUsed) { iter->second.walk.bUsed = true; updateOtherPlayer(iter->second.walk.uid, iter->second.walk.pt, iter->second.walk.animID, iter->second.walk.bFlip); } else { iter->second.idleTime.curTime += dt; } } while(!LevelManager::sShareInstance()->m_otherPlayerInfo.empty()) { const LevelManager::OTHER_PLAYER_INFO& info = LevelManager::sShareInstance()->m_otherPlayerInfo.top(); m_levelBuilder->addOtherPlayer(info.uid, info.userName.c_str(), info.type, info.pos, info.orient, info.battleSide); LevelManager::sShareInstance()->m_otherPlayerInfo.pop(); } CCArray* children = this->getChildren(); if (children) { int childrenCount = children->count(); for (int i = 0; i < childrenCount; ++i) { CCNode* child = (CCNode* )children->objectAtIndex(i); ASSERT(child != NULL, "child is NULL"); BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag()); if (listener) { listener->HandleLayerUpdateEvent(child, dt); } } } if(m_pObjectsLayer != NULL) { children = m_pObjectsLayer->getChildren(); if (children) { int childrenCount = children->count(); for (int i = 0; i < childrenCount; ++i) { CCNode* child = (CCNode* )children->objectAtIndex(i); ASSERT(child != NULL, "child is NULL"); BaseListener* listener = LevelLayer::sGetListenerByTag(child->getTag()); if (listener) { listener->HandleLayerUpdateEvent(child, dt); } } } } // update Hero SpriteSeer* hero = GameManager::Get()->getHero(); if (hero) { hero->Update(dt); } //更新其他玩家 std::map<uint32_t, OthersPlayerInfo>::iterator itor = m_othersPlayerInfo.begin(); while (itor != m_othersPlayerInfo.end()) { OthersPlayerInfo playerInfo = (*itor).second; SpriteSeer * seer = playerInfo.seer; if (seer) { seer->Update(dt); } itor++; } // update ItemUpdatManager ItemUpdateManager::Get()->Update(dt); // update monster SpriteMonsterMgr::Get()->Update(dt); // update actor EnginePlayerManager::getInstance()->update(dt); // Note: Update SpriteElf SpriteElfManager::Get()->Update(dt); // Note: 剧情Update StoryInstanceDirector::Get()->Update(dt); //按住屏幕移动持续寻路 if (pressTime < 0.1f) { pressTime += dt; } else if (m_touchWinPoint.x != 0 && m_touchWinPoint.y != 0) { float deviceScale = CCDirector::sharedDirector()->getContentScaleFactor(); m_touchWinPoint = CCPoint(m_touchWinPoint.x * deviceScale, m_touchWinPoint.y * deviceScale); CCPoint newPT = LevelMultiResolution::sTransformWindowPointToMap(m_touchWinPoint); SpriteSeer * hero = GameManager::Get()->getHero(); if (hero) { BaseListener* listener = LevelLayer::sGetListenerByTag(hero->getTag()); if (listener) { listener->HandleLayerTouchBeginEvent(hero, newPT); } } pressTime = 0.0f; } SkillDispMgr::Get()->Update(dt); PvAIManager::Get()->Update(dt); }