void BaseLevelBuilder::removeOtherPlayer(unsigned int uid) { // Note: Remove Attach Elf SpriteFactory::sharedFactory()->RemoveElfFromHero(uid); std::map<unsigned int, LevelLayer::WAKL_INFO>::iterator iterWalk = m_level->m_walkInfo.find(uid); if(iterWalk != m_level->m_walkInfo.end()) { m_level->m_walkInfo.erase(iterWalk); } std::map<uint32_t, OthersPlayerInfo>::iterator itor = m_level->m_othersPlayerInfo.find(uid); if (itor != m_level->m_othersPlayerInfo.end()) { OthersPlayerInfo playerInfo = (*itor).second; // m_level->m_othersPlayerInfo.erase(itor); //remove seer SpriteSeer* seer = playerInfo.seer; if (seer && m_level->m_pObjectsLayer) { seer->getRoot()->stopAllActions(); m_level->m_pObjectsLayer->removeChild(seer, true); } } else { CCLog("error, the player has not add before"); } }
void StoryInstanceDirector::RemoveAndClearRcs() { std::map<unsigned int,SpriteSeer*>::iterator iter = m_mapRoleIdAndInstance.begin(); while(iter != m_mapRoleIdAndInstance.end()) { SpriteSeer* pSeer = (*iter).second; if (m_heroIndex == (*iter).first) { pSeer->getRoot()->setVisible(true); } else { //pSeer->getParent()->removeChild(pSeer,true); pSeer->getRoot()->setVisible(false); } iter ++; } m_mapRoleIdAndInstance.clear(); }
void StoryInstanceDirector::LoadAllRoles() { std::vector<unsigned int> vecOut; if (StoryDataCenter::Get()->GetOneItemAllRoleIds(vecOut)) { size_t count = vecOut.size(); for (size_t index = 0;index<count;index++) { unsigned int roleId = vecOut[index]; SpriteSeer* pSeer = 0; if (roleId != 0) { pSeer = InsertOneRole(index+1,roleId); unsigned int seerTypeId = pSeer->GetTypeId(); if (false == SpriteElfConfigFromLuaManager::getInstance()->TellIsElfId(seerTypeId)) { ASprite* pAsprite = AspriteManager::getInstance()->getAsprite("spriteBin/shadow.bin"); if(pAsprite != NULL) { CCPoint cp; CCSpriteBatchNode* pBatchNode = pAsprite->getSpriteBatchNodeFromFrame_Middle(0, 0, cp); if(pBatchNode != NULL) { pSeer->addChildToRoot(pBatchNode); } } } } else { pSeer = GameManager::Get()->getHero(); pSeer = InsertOneRole(index+1,roleId,pSeer); if (pSeer) { m_heroIndex = index+1; } } if (pSeer) { pSeer->getRoot()->setVisible(false); } } } }
bool StoryInstanceDirector::TrackPlayerAnim() { // Note: Add To Obj Layer LevelLayer* pLayer = LevelManager::sShareInstance()->getCurrentLevelLayer(); CCNode* pObjLayer = pLayer->getObjectLayer(); std::map<unsigned int,StoryRoleBasicData> storyData = StoryDataCenter::Get()->GetStoryRoleBasicData(); std::map<unsigned int,StoryRoleBasicData>::iterator iter = storyData.begin(); while(iter != storyData.end()) { bool bPosChanged = false; SpriteSeer* pCurHero = GetOneRole((*iter).first); std::map<unsigned int,StoryFrameData>::iterator frameIter = (*iter).second.mMapStoryFramesData.find((int)m_curFrame); if (frameIter != (*iter).second.mMapStoryFramesData.end()) { //// Note: 当前帧存在 StoryFrameData frameData = (*frameIter).second; CCPoint pos = frameData.getRolePos(); // Note: 位置发生变化,移动位置,或者新创建角色 if (StoryFrameData::IsPosChanged(pos)) { bPosChanged = true; bool bVisiable = pCurHero->getRoot()->isVisible(); if (bVisiable == false) { pCurHero->getRoot()->setVisible(true); } pCurHero->setPosition(pos); pObjLayer->reorderChild(pCurHero,LevelLayer::sCalcZorder(pos)); } int actorId = frameData.getActorId(); if (actorId != -1) { pCurHero->SetAnim(actorId,0); } int nFlip = frameData.getFlip(); if (nFlip != -1) { if (nFlip == 0) { pCurHero->SetAnimFlipX(false); } else if (nFlip == 1) { pCurHero->SetAnimFlipX(true); } } } if (false == bPosChanged) { // Note: 不存在的情况下处理移动 if (false == bPosChanged) { unsigned int preFrameIndex = 0; unsigned int nextFrameIndex = 0; CCPoint prePoint = CCPointZero; CCPoint nextPoint = CCPointZero; if(StoryDataCenter::Get()->GetPreAndNextPointFrameData((*iter).first,(int)m_curFrame,preFrameIndex,nextFrameIndex,prePoint,nextPoint)) { // Note: 处理移动 unsigned int sumMoveFrames = (nextFrameIndex - preFrameIndex); unsigned int runningFrames = (int)m_curFrame - preFrameIndex; if (runningFrames >= sumMoveFrames) { return false; } // Note: 运动速率 CCPoint dir = ccpSub(nextPoint,prePoint); float distance = sqrt(ccpLengthSQ(dir)); float vPerFrame = distance/sumMoveFrames; if(dir.x == 0 && dir.y == 0) { return false; } dir = ccpNormalize(dir); CCPoint nowPoint = ccpAdd(prePoint,ccp(vPerFrame*runningFrames*dir.x,vPerFrame*runningFrames*dir.y)); pCurHero->setPosition(nowPoint); pObjLayer->reorderChild(pCurHero,LevelLayer::sCalcZorder(nowPoint)); } } } iter++; } return true; }