void YHLanguageManager::addTexts(cocos2d::CCDictionary * dict) { CCDictElement * e = nullptr; CCDICT_FOREACH(dict, e) { m_dict->setObject(e->getObject(), e->getStrKey()); }
void CCPrettyPrinter::visit(const CCDictionary *p) { _result += "\n"; _result += _indentStr; _result += "<dict>\n"; setIndentLevel(_indentLevel+1); CCDictElement* element; bool bFirstElement = true; char buf[1000] = {0}; CCDICT_FOREACH(p, element) { if (!bFirstElement) { _result += "\n"; } sprintf(buf, "%s%s: ", _indentStr.c_str(),element->getStrKey()); _result += buf; CCPrettyPrinter v(_indentLevel); element->getObject()->acceptVisitor(v); _result += v.getResult(); bFirstElement = false; } setIndentLevel(_indentLevel-1); _result += "\n"; _result += _indentStr; _result += "</dict>"; }
CCArray * GAFAsset::objectStatesFromConfigFrame(CCDictionary * configFrame) { if (!configFrame) { return NULL; } CCDictionary * stateNodes = (CCDictionary *) configFrame->objectForKey(kFrameStateKey); if (!stateNodes) { return NULL; } CCArray *states = CCArray::createWithCapacity(stateNodes->count()); CCDictElement* pElement = NULL; CCDICT_FOREACH(stateNodes, pElement) { CCDictionary * stateDictionary = (CCDictionary *)pElement->getObject(); GAFSubobjectState * state = GAFSubobjectState::createWithStateDictionary(stateDictionary, pElement->getStrKey()); if (state) { states->addObject(state); } else { CCLOGINFO("GAFSubobjectState cannot be created. Ignoring."); } }
void StatusPush::handleResponse(__Dictionary* dict) { if (!dict) { return; } __Dictionary* params = _dict(dict->objectForKey("params")); if (params->objectForKey("oldStatus")) {//删除该状态的作用 int reStatusId = params->valueForKey("oldStatus")->intValue(); if (GlobalData::shared()->statusMap.find(reStatusId) != GlobalData::shared()->statusMap.end()) { GlobalData::shared()->statusMap[reStatusId] = 0; } } // int tempTime = 0; if (params->objectForKey("effectState")) { auto stateDict = _dict(params->objectForKey("effectState")); CCDictElement* element; CCDICT_FOREACH(stateDict, element) { string key = element->getStrKey(); // int effectId = atoi(key.c_str()); double time = stateDict->valueForKey(key)->doubleValue()/1000; if (time>0) { time = GlobalData::shared()->changeTime(time); } if (key!="startTime") { GlobalData::shared()->statusMap[atoi(key.c_str())] = -1;//time; // tempTime = time; } map<int, CCDictionary* >::iterator it = ToolController::getInstance()->m_statusItems.find(100); CCObject* obj = element->getObject(); CCString* str = (CCString*)obj; if(it!=ToolController::getInstance()->m_statusItems.end()){ auto dic = it->second; if(!dic->objectForKey("startTime")){ dic->setObject(CCString::create(CC_ITOA(WorldController::getInstance()->getTime())), "startTime"); }else if(key!="" && key!="startTime"){ dic->setObject(CCString::create(str->getCString()), "endTime"); }else if(key=="startTime"){ dic->setObject(CCString::create(str->getCString()), "startTime"); } ToolController::getInstance()->m_statusItems[100] = dic; }else{ auto infoDic = CCDictionary::create(); infoDic->retain(); if(key!="" && key!="startTime"){ infoDic->setObject(CCString::create(str->getCString()), "endTime"); }else if(key=="startTime"){ infoDic->setObject(CCString::create(str->getCString()), "startTime"); } ToolController::getInstance()->m_statusItems[100] = infoDic; } ToolController::getInstance()->checkMaincityCustom(); }
bool CCDictionarySaver::saveDictionary(CCDictionary* pDict, xmlNodePtr node) { do { xmlNodePtr dict_node = xmlNewNode(NULL, DICT_NODE_DICT); CC_BREAK_IF(!dict_node); CC_BREAK_IF(!xmlAddChild(node, dict_node)); CCDictElement* pElem; CCDICT_FOREACH(pDict, pElem) { saveKey(pElem->getStrKey(), dict_node); CCObject* obj = pElem->getObject(); if (dynamic_cast<CCString*>(obj)) { CCString* s = dynamic_cast<CCString*>(obj); CC_BREAK_IF(!saveString(s->getCString(), dict_node)); } else if (dynamic_cast<CCDictionary*>(obj)) { CC_BREAK_IF(!saveDictionary(dynamic_cast<CCDictionary*>(obj), dict_node)); } else if (dynamic_cast<CCArray*>(obj)) { CC_BREAK_IF(!saveArray(dynamic_cast<CCArray*>(obj), dict_node)); } } return true; } while (false);
bool BattleMap::f_load_entile() { do { b2CircleShape circle; b2BodyDef ballBodyDef; ballBodyDef.type = b2_dynamicBody; circle.m_radius = 16.0/PTM_RATIO; b2FixtureDef ballShapeDef; ballShapeDef.shape = &circle; ballShapeDef.density = 1.0f; ballShapeDef.friction = 1.0f; ballShapeDef.restitution = 0.0f; ballShapeDef.isSensor = true; // 将碰撞形状改为sensor不会提高多少效率却会破坏map原本事件机制。 //// b2body准备工作 ////////////////////////////////////////////////////////////////////////// CCSize ts = m_tilemap->getTileSize(); b2PolygonShape boxShape; float hbw = (ts.width-1)/( PTM_RATIO * 4); float hbh = (ts.height-1)/( PTM_RATIO); hbh *= 1.2; boxShape.SetAsBox(hbw,hbh,b2Vec2(0,hbh),0); CCDictElement* cde = NULL; CCDICT_FOREACH(m_itemlist,cde){ EChesses* t_ec = (EChesses*) cde->getObject(); t_ec->initFiles("grossinis_sister2.png"); CCPoint d = m_getViewc(t_ec->pos); t_ec->m_sprite->setAnchorPoint(ccp(0,0)); t_ec->b_Re = true; addChild(t_ec->m_sprite); ballBodyDef.position.Set((dtx+d.x)/PTM_RATIO, (d.y+dty)/PTM_RATIO); _body = _world->CreateBody(&ballBodyDef); _body->SetFixedRotation(true); _body->CreateFixture(&ballShapeDef); t_ec->m_body = _body; _body->SetUserData(t_ec); b2FixtureDef boxFixtureDef; boxFixtureDef.shape = &boxShape; boxFixtureDef.density = 1; boxFixtureDef.filter.categoryBits = 0x0002; boxFixtureDef.filter.maskBits = 0x0001; boxFixtureDef.isSensor = true; _body->CreateFixture(&boxFixtureDef); } // EChesses in BattleMap has its own logic, so a logic based on sensor is no longer needed. return true; } while (0);
void CCJSONConverter::convertDictionaryToJson(CCDictionary *dictionary, cJSON *json) { CCDictElement * pElement = NULL; CCDICT_FOREACH(dictionary, pElement){ CCObject * obj = pElement->getObject(); cJSON * jsonItem = getObjJson(obj); cJSON_AddItemToObject(json, pElement->getStrKey(), jsonItem); }
void CCBProxy::releaseMembers(){ CCDictElement *e; CCNode *n; CCDICT_FOREACH(_memVars, e){ n = (CCNode *)e->getObject(); n->removeFromParentAndCleanup(true); n->autorelease(); }
void CCProfiler::displayTimers() { CCDictElement* pElement = NULL; CCDICT_FOREACH(m_pActiveTimers, pElement) { CCProfilingTimer* timer = (CCProfilingTimer*)pElement->getObject(); CCLog("%s", timer->description()); }
CCDictionary* CCTextureCache::snapshotTextures() { CCDictionary* pRet = new CCDictionary(); CCDictElement* pElement = NULL; CCDICT_FOREACH(m_pTextures, pElement) { pRet->setObject(pElement->getObject(), pElement->getStrKey()); }
void BZGameMenu::onUpdate() { CCDictElement* pElement = NULL; CCDICT_FOREACH(_bars, pElement) { BZGameMenuBar* pbar = (BZGameMenuBar*)pElement->getObject(); _Assert(pbar); pbar->onUpdate(); }
void YHEffectFactory::addEffectDefiner(CCDictionary * dict) { CCDictElement * e = NULL; CCDICT_FOREACH(dict, e) { YHEffectDefiner * definer = new YHEffectDefiner((CCDictionary *)e->getObject()); definer->autorelease(); addEffectDefiner(e->getStrKey(), definer); }
CCArray* MultiplayerGameState::getAllOpponents() { if (_opponentsSprite == NULL || _opponentsSprite->count() <= 0) return NULL; CCArray* opponents = CCArray::createWithCapacity(_opponentsSprite->count()); CCDictElement* dictElement = NULL; CCDICT_FOREACH(_opponentsSprite, dictElement) { opponents->addObject((Opponent*)dictElement->getObject()); }
void BBTouchManager::saveTouches() { CCDictElement* pElement; BBTouchInfo* touchInfo = BBTouchInfo::create(); CCDICT_FOREACH(m_pTouches, pElement) { CCTouch* v = (CCTouch*)pElement->getObject(); touchInfo->touches.push_back(v->getLocation()); }
void Animal::clean(){ this->finishCurAction(); this->stopAllActions(); this->getObserver()->finish(); CCDictElement* pElement = NULL; CCDICT_FOREACH(moves, pElement) { int key = pElement->getIntKey(); BaseMove* move = (BaseMove*)pElement->getObject(); this->removeChild(move,true); }
GameEntity::~GameEntity() { CCLOG("GameEntity destroy"); // CC_SAFE_RELEASE(m_view); CCDictElement* pElement = NULL; CCDICT_FOREACH(m_components,pElement){ Component* component=(Component*)pElement->getObject(); component->cleanupMessages(); }
DBData::~DBData() { CCDictElement* pElement = NULL; CCDICT_FOREACH(m_dic, pElement) { CCObject* pObj = pElement->getObject(); if (pObj) { pObj->release(); } }
void SportLayer::hideAllPanels() { CCAssert(m_allPanelNames != NULL , "m_allPanelNames is not init!"); Layout* lay = NULL; CCDictElement* elm = NULL; CCDICT_FOREACH(m_allPanelNames , elm){ lay = dynamic_cast<Layout*>(m_pUILayer->getWidgetByName(((CCString* )elm->getObject())->getCString() )); if(! lay) continue; lay->setVisible(false); lay->setTouchEnable(false,true); }
// // load file // void CCConfiguration::loadConfigFile( const char *filename ) { CCDictionary *dict = CCDictionary::createWithContentsOfFile(filename); CCAssert(dict, "cannot create dictionary"); // search for metadata bool metadata_ok = false; CCObject *metadata = dict->objectForKey("metadata"); if( metadata && dynamic_cast<CCDictionary*>(metadata) ) { CCObject *format_o = static_cast<CCDictionary*>(metadata)->objectForKey("format"); // XXX: cocos2d-x returns CCStrings when importing from .plist. This bug will be addressed in cocos2d-x v3.x if( format_o && dynamic_cast<CCString*>(format_o) ) { int format = static_cast<CCString*>(format_o)->intValue(); // Support format: 1 if( format == 1 ) { metadata_ok = true; } } // XXX: cocos2d-x returns CCStrings when importing from .plist. This bug will be addressed in cocos2d-x v3.x if( format_o && dynamic_cast<CCInteger*>(format_o) ) { int format = dynamic_cast<CCInteger*>(format_o)->getValue(); // Support format: 1 if( format == 1 ) { metadata_ok = true; } } } if( ! metadata_ok ) { CCLOG("Invalid config format for file: %s", filename); return; } CCObject *data = dict->objectForKey("data"); if( !data || !dynamic_cast<CCDictionary*>(data) ) { CCLOG("Expected 'data' dict, but not found. Config file: %s", filename); return; } // Add all keys in the existing dictionary CCDictionary *data_dict = static_cast<CCDictionary*>(data); CCDictElement* element; CCDICT_FOREACH(data_dict, element) { if( ! m_pValueDict->objectForKey( element->getStrKey() ) ) m_pValueDict->setObject(element->getObject(), element->getStrKey() ); else CCLOG("Key already present. Ignoring '%s'", element->getStrKey() ); } }
void CCAnimationCache::parseVersion1(CCDictionary* animations) { CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); CCDictElement* pElement = NULL; CCDICT_FOREACH(animations, pElement) { CCDictionary* animationDict = (CCDictionary*)pElement->getObject(); CCArray* frameNames = (CCArray*)animationDict->objectForKey("frames"); float delay = animationDict->valueForKey("delay")->floatValue(); CCAnimation* animation = NULL; if ( frameNames == NULL ) { CCLOG("cocos2d: CCAnimationCache: Animation '%s' found in dictionary without any frames - cannot add to animation cache.", pElement->getStrKey()); continue; } CCArray* frames = CCArray::createWithCapacity(frameNames->count()); frames->retain(); CCObject* pObj = NULL; CCARRAY_FOREACH(frameNames, pObj) { const char* frameName = ((CCString*)pObj)->getCString(); CCSpriteFrame* spriteFrame = frameCache->spriteFrameByName(frameName); if ( ! spriteFrame ) { CCLOG("cocos2d: CCAnimationCache: Animation '%s' refers to frame '%s' which is not currently in the CCSpriteFrameCache. This frame will not be added to the animation.", pElement->getStrKey(), frameName); continue; } CCAnimationFrame* animFrame = new CCAnimationFrame(); animFrame->initWithSpriteFrame(spriteFrame, 1, NULL); frames->addObject(animFrame); animFrame->release(); } if ( frames->count() == 0 ) { CCLOG("cocos2d: CCAnimationCache: None of the frames for animation '%s' were found in the CCSpriteFrameCache. Animation is not being added to the Animation Cache.", pElement->getStrKey()); continue; } else if ( frames->count() != frameNames->count() ) { CCLOG("cocos2d: CCAnimationCache: An animation in your dictionary refers to a frame which is not in the CCSpriteFrameCache. Some or all of the frames for the animation '%s' may be missing.", pElement->getStrKey()); } animation = CCAnimation::create(frames, delay, 1); CCAnimationCache::sharedAnimationCache()->addAnimation(animation, pElement->getStrKey()); frames->release(); }
// // load file // void CCConfiguration::loadConfigFile( const char *filename ) { CCDictionary *dict = CCDictionary::createWithContentsOfFile(filename); CCAssert(dict, "cannot create dictionary"); // Add all keys in the existing dictionary CCDictElement* element; CCDICT_FOREACH(dict, element) { if( ! m_pDefaults->objectForKey( element->getStrKey() ) ) m_pDefaults->setObject(element->getObject(), element->getStrKey() ); else CCLOG("Key already present. Ignoring '%s'", element->getStrKey() ); } }
bool AmfUtil::isSame(cocos2d::CCObject *thisObj, cocos2d::CCObject *thatObj) { if (thisObj && !thatObj) return false; if (!thisObj && thatObj) return false; if (!thisObj && !thatObj) return true; if (dynamic_cast<CCBool *>(thisObj) && dynamic_cast<CCBool *>(thatObj)) { return dynamic_cast<CCBool *>(thisObj)->getValue() == dynamic_cast<CCBool *>(thatObj)->getValue(); } else if (dynamic_cast<CCInteger *>(thisObj) && dynamic_cast<CCInteger *>(thatObj)) { return dynamic_cast<CCInteger *>(thisObj)->getValue() == dynamic_cast<CCInteger *>(thatObj)->getValue(); } else if (dynamic_cast<CCFloat *>(thisObj) && dynamic_cast<CCFloat *>(thatObj)) { return dynamic_cast<CCFloat *>(thisObj)->getValue() == dynamic_cast<CCFloat *>(thatObj)->getValue(); } else if (dynamic_cast<CCDouble *>(thisObj) && dynamic_cast<CCDouble *>(thatObj)) { return dynamic_cast<CCDouble *>(thisObj)->getValue() == dynamic_cast<CCDouble *>(thatObj)->getValue(); } else if (dynamic_cast<CCString *>(thisObj) && dynamic_cast<CCString *>(thatObj)) { return strcmp(dynamic_cast<CCString *>(thisObj)->getCString(), dynamic_cast<CCString *>(thatObj)->getCString()) == 0; } else if (dynamic_cast<CCDate *>(thisObj) && dynamic_cast<CCDate *>(thatObj)) { return dynamic_cast<CCDate *>(thisObj)->isEqual(dynamic_cast<CCDate *>(thatObj)); } else if (dynamic_cast<AmfTraitsInfo *>(thisObj) && dynamic_cast<AmfTraitsInfo *>(thatObj)) { return dynamic_cast<AmfTraitsInfo *>(thisObj)->isEqual(dynamic_cast<AmfTraitsInfo *>(thatObj)); } else if (dynamic_cast<AmfObject *>(thisObj) && dynamic_cast<AmfObject *>(thatObj)) { return dynamic_cast<AmfObject *>(thisObj)->isEqual(dynamic_cast<AmfObject *>(thatObj)); } else if (dynamic_cast<AmfCoding *>(thisObj) && dynamic_cast<AmfCoding *>(thatObj)) { return dynamic_cast<AmfCoding *>(thisObj)->isEquals(thatObj); } else if (dynamic_cast<CCArray *>(thisObj) && dynamic_cast<CCArray *>(thatObj)) { CCArray *thisArray = dynamic_cast<CCArray *>(thisObj); CCArray *thatArray = dynamic_cast<CCArray *>(thatObj); int count = thisArray->count(); int capacity = thisArray->capacity(); if (count != thatArray->count() || (count == 0 && capacity != thatArray->capacity())) return false; for (int i = 0; i < count; i++) { if (!isSame(thisArray->objectAtIndex(i), thatArray->objectAtIndex(i))) return false; } return true; } else if (dynamic_cast<CCDictionary *>(thisObj) && dynamic_cast<CCDictionary *>(thatObj)) { CCDictionary *thisDict = dynamic_cast<CCDictionary *>(thisObj); CCDictionary *thatDict = dynamic_cast<CCDictionary *>(thatObj); int count = thisDict->count(); if (count != thatDict->count()) return false; CCDictElement *thisElement; CCDICT_FOREACH(thisDict, thisElement) { char const *thisKey = thisElement->getStrKey(); CCObject *thatValue = thatDict->objectForKey(thisKey); if (!thatValue) return false; if (!isSame(thisElement->getObject(), thatValue)) return false; }
void CCControlButton::setPreferredSize(CCSize size) { if(size.width == 0 && size.height == 0) { m_doesAdjustBackgroundImage = true; } else { m_doesAdjustBackgroundImage = false; CCDictElement * item = NULL; CCDICT_FOREACH(m_backgroundSpriteDispatchTable, item) { CCScale9Sprite* sprite = (CCScale9Sprite*)item->getObject(); sprite->setPreferredSize(size); } }
void TestColliderDetector::update(float delta) { armature2->setVisible(true); CCRect rect = bullet->boundingBox(); // This code is just telling how to get the vertex. // For a more accurate collider detection, you need to implemente yourself. CCDictElement *element = NULL; CCDictionary *dict = armature2->getBoneDic(); CCDICT_FOREACH(dict, element) { CCBone *bone = static_cast<CCBone*>(element->getObject()); CCArray *bodyList = bone->getColliderBodyList(); CCObject *object = NULL; CCARRAY_FOREACH(bodyList, object) { ColliderBody *body = static_cast<ColliderBody*>(object); CCArray *vertexList = body->getCalculatedVertexList(); float minx, miny, maxx, maxy = 0; int length = vertexList->count(); for (int i = 0; i<length; i++) { CCContourVertex2 *vertex = static_cast<CCContourVertex2*>(vertexList->objectAtIndex(i)); if (i == 0) { minx = maxx = vertex->x; miny = maxy = vertex->y; } else { minx = vertex->x < minx ? vertex->x : minx; miny = vertex->y < miny ? vertex->y : miny; maxx = vertex->x > maxx ? vertex->x : maxx; maxy = vertex->y > maxy ? vertex->y : maxy; } } CCRect temp = CCRectMake(minx, miny, maxx - minx, maxy - miny); if (temp.intersectsRect(rect)) { armature2->setVisible(false); } }
void ArmatureDataManager::removeUnusedAnimations(){ if( m_pArmatureFileInfoDic ){ CCTextureCache * tc = CCTextureCache::sharedTextureCache(); CCSpriteFrameCache * sfc = CCSpriteFrameCache::sharedSpriteFrameCache(); std::vector<std::string> cleanlist; CCDictElement* pElement = NULL; CCDICT_FOREACH(m_pArmatureFileInfoDic, pElement){ const std::string file = pElement->getStrKey(); ArmatureFileInfo * _fileInfo = (ArmatureFileInfo*)pElement->getObject(); if (_fileInfo && _fileInfo->retainCount() == 1) { //清理 m_pAnimationDatas、m_pArmarureDatas、m_pTextureDatas 信息 if( m_pAnimationDatas ){ m_pAnimationDatas->removeObjectForKey(_fileInfo->configFilePath); } if( m_pArmarureDatas ){ m_pArmarureDatas->removeObjectForKey(_fileInfo->configFilePath); } if( m_pTextureDatas ){ m_pTextureDatas->removeObjectForKey(_fileInfo->configFilePath); } //清理精灵帧、纹理和标记需要清理的ArmatureFile for (std::vector<ImageInfo>::iterator it = _fileInfo->imageInfoVector.begin(); it != _fileInfo->imageInfoVector.end(); it++){ const std::string & plist = it->plistPath; const std::string & texture = it->imagePath; sfc->removeSpriteFramesFromFile(plist.c_str()); tc->removeTextureForKey(texture.c_str()); cleanlist.push_back(file); } } } int size = cleanlist.size(); for(int i = 0; i < size; i++) { m_pArmatureFileInfoDic->removeObjectForKey(cleanlist[i]); } cleanlist.clear(); } }
CCArray* ItemStatusView::getTypeArray(int type){ int city_lv = FunBuildController::getInstance()->getMainCityLv(); auto goodDic = LocalController::shared()->DBXMLManager()->getGroupByKey("goods"); CCArray* array = CCArray::create();// new CCArray(); // array->init(); int num = 0; if(goodDic) { CCDictElement* element; CCDICT_FOREACH(goodDic, element) { CCDictionary* dictInfo = _dict(element->getObject()); if(type==dictInfo->valueForKey("type2")->intValue() && dictInfo->valueForKey("type")->intValue()==4 && city_lv>=dictInfo->valueForKey("lv")->intValue()){ array->addObject(dictInfo); } } }
ValueMap valueMapFromDictionary(CCDictionary * root) { assert(root != NULL); ValueMap map; CCDictElement * e = NULL; CCDICT_FOREACH(root, e) { CCObject * obj = e->getObject(); if (dynamic_cast<CCString *>(obj) != NULL) { CCString * str = (CCString *)obj; map[e->getStrKey()] = cocos2d::Value(str->getCString()); } else if (dynamic_cast<CCFloat *>(obj) != NULL) { CCFloat * val = (CCFloat *)obj; map[e->getStrKey()] = cocos2d::Value(val->getValue()); } else if (dynamic_cast<CCDouble *>(obj) != NULL) { CCDouble * val = (CCDouble *)obj; map[e->getStrKey()] = cocos2d::Value(val->getValue()); } else if (dynamic_cast<CCInteger *>(obj) != NULL) { CCInteger * val = (CCInteger *)obj; map[e->getStrKey()] = cocos2d::Value(val->getValue()); } else if (dynamic_cast<CCBool *>(obj) != NULL) { CCBool * val = (CCBool *)obj; map[e->getStrKey()] = cocos2d::Value(val->getValue()); } else if (dynamic_cast<CCDictionary *>(obj) != NULL) { CCDictionary * dict = (CCDictionary *)obj; map[e->getStrKey()] = cocos2d::Value(valueMapFromDictionary(dict)); } else if (dynamic_cast<CCArray *>(obj) != NULL) { CCArray * arr = (CCArray *)obj; map[e->getStrKey()] = cocos2d::Value(valueVectorFromArray(arr)); } }
// initialize NPC names void NPCManager::initNpcNames() { // read NpcName.plist const char* pszPath = GameResourceManager::sharedManager()->storedFullPathFromRelativePath(NPC_NAME_PLIST); CCDictionary *pNameDict = CCFileUtils::dictionaryWithContentsOfFile(pszPath); CCDictElement* pElement = NULL; CCDICT_FOREACH(pNameDict, pElement) { if (pNameDict->objectForKey(pElement->getStrKey())) { string strNpcID = pElement->getStrKey(); string strName = ((CCString*)pElement->getObject())->toStdString(); uint8 npcID = atoi(strNpcID.c_str()); m_npcName[npcID] = strName; } } }
bool Cartoon::ccTouchBegan(cocos2d::CCTouch *touch, cocos2d::CCEvent *event) { CCPoint touchLocation = touch->getLocationInView(); touchLocation = CCDirector::sharedDirector()->convertToGL(touchLocation); touchLocation = convertToNodeSpace(touchLocation); // from left-bottom point to from left-top point touchLocation.y = getContentSize().height - touchLocation.y; if (m_pListener && m_pfnSelector) { CCDictElement* pElement = NULL; CCDICT_FOREACH(m_pBoxConfigs, pElement) { CCString *psBox = (CCString*)pElement->getObject(); CCRect rectOfTouched = CCRectFromString(psBox->m_sString.c_str()); if (rectOfTouched.containsPoint(touchLocation) && getBoxEnabled(pElement->getStrKey())) { (m_pListener->*m_pfnSelector)(this, pElement->getStrKey()); } }
bool CallbackExplode::doCallback(GameObject * aGameObject,CCDictionary * dic,float dt) { if (dic && aGameObject) { //获得效果本身影响的范围 CCDictionary * property = (CCDictionary *)aGameObject->getValue(KStrProperty); CCString * atkStr = (CCString *)property->objectForKey(KStrATK); CCString * atkRangeStr = (CCString *)property->objectForKey(KStrATK_RANGE); float atk_range_org = (atkRangeStr?atkRangeStr->floatValue():0) * 0.5; float atk = atkStr? atkStr->floatValue() : 0; //获得对应的效果播放的中心点 CCDictionary * pDict=(CCDictionary *)dic->objectForKey(KStrPosition); CCString * paramStr=(CCString *)dic->objectForKey(KStrParam); float scale = !paramStr ? 1.0 : paramStr->floatValue(); float atk_range = scale * atk_range_org; CCPoint p = GameObject::dict2Point(pDict); GameModle * _sharedInstance = GameModle::sharedInstance(); CCDictionary * objects = _sharedInstance->gameObjectsDict(); CCDictElement * pDictElement = NULL; CCDICT_FOREACH(objects, pDictElement){ int32_t classid=pDictElement->getIntKey(); if(KNPCTypeId == GameObject::typeIdOfClassId(classid)){ CCSet * set=(CCSet*)pDictElement->getObject(); CCSetIterator iter; for (iter = set->begin(); iter != set->end(); ++iter) { GameObject * tmp=(GameObject *)(*iter); if (tmp->isActive()) { float r = tmp->getContentSize().width * 0.5; //检测可以攻击到泡泡 if(GameObject::isCircleContact(p,atk_range,tmp->getPosition(),r)){ //处理进入到攻击范围的泡泡 handleExplode(tmp,NULL,atk,aGameObject); } } } } }