void MCItemManager::loadEquipmentItems() { JsonBox::Value weapon; JsonBox::Value armor; JsonBox::Object root; JsonBox::Object::iterator rootIterator; MCOreManager *oreManager = MCOreManager::sharedOreManager(); /* 读取武器 */ #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) CCString* pstrFileContent = CCString::createWithContentsOfFile(kMCEquipmentItemWeaponFilepath); if (pstrFileContent) { weapon.loadFromString(pstrFileContent->getCString()); } #else weapon.loadFromFile(CCFileUtils::sharedFileUtils()->fullPathForFilename(kMCEquipmentItemWeaponFilepath).c_str()); #endif root = weapon.getObject(); for (rootIterator = root.begin(); rootIterator != root.end(); ++rootIterator) { const char *c_str_o_id = rootIterator->first.c_str(); JsonBox::Object object = rootIterator->second.getObject(); mc_object_id_t o_id = { c_str_o_id[0], c_str_o_id[1], c_str_o_id[2], c_str_o_id[3] }; MCEquipmentItem *item = MCEquipmentItem::create(MCEquipment::MCWeapon); CCString *ccstring; item->setID(o_id); ccstring = CCString::create(object["name"].getString().c_str()); item->setName(ccstring); ccstring->retain(); ccstring = CCString::create(object["icon"].getString().c_str()); item->setIcon(ccstring); ccstring->retain(); item->setPrice(object["price"].getInt()); JsonBox::Object damage = object["damage"].getObject(); MCWeapon *equipment = dynamic_cast<MCWeapon *>(item->equipment_); /* effect-id */ c_str_o_id = object["effect-id"].getString().c_str(); mc_object_id_t e_id = { c_str_o_id[0], c_str_o_id[1], c_str_o_id[2], c_str_o_id[3] }; MCEffectManager *effectManager = MCEffectManager::sharedEffectManager(); MCEffect *effect = effectManager->effectForObjectId(e_id); equipment->attackEffect = effect; effect->retain(); equipment->damage = MCMakeDiceType(damage["count"].getInt(), damage["size"].getInt()); equipment->criticalHit = object["critical-hit"].getInt(); JsonBox::Object diceRange = object["critical-hit-visible"].getObject(); JsonBox::Object diceRangeDice = diceRange["dice"].getObject(); equipment->criticalHitVisible.min = diceRange["min"].getInt(); equipment->criticalHitVisible.max = diceRange["max"].getInt(); equipment->criticalHitVisible.dice = MCMakeDiceType(diceRangeDice["count"].getInt(), diceRangeDice["size"].getInt()); diceRange = object["critical-hit-invisible"].getObject(); diceRangeDice = diceRange["dice"].getObject(); equipment->criticalHitInvisible.min = diceRange["min"].getInt(); equipment->criticalHitInvisible.max = diceRange["max"].getInt(); equipment->criticalHitInvisible.dice = MCMakeDiceType(diceRangeDice["count"].getInt(), diceRangeDice["size"].getInt()); equipment->distance = object["distance"].getInt(); if (object["effect"].isInteger()) { equipment->effect = object["effect"].getInt(); diceRange = object["effect-check"].getObject(); diceRangeDice = diceRange["dice"].getObject(); equipment->effectCheck.min = diceRange["min"].getInt(); equipment->effectCheck.max = diceRange["max"].getInt(); equipment->effectCheck.dice = MCMakeDiceType(diceRangeDice["count"].getInt(), diceRangeDice["size"].getInt()); } else { equipment->effect = MCNormalState; } /* consume Double */ equipment->consume = object["consume"].isDouble() ? (float) object["consume"].getDouble() : (float) object["consume"].getInt(); equipment->dexterity = object["dexterity"].getInt(); /* action-effect String */ equipment->actionEffect.assign(object["action-effect"].getString()); /* 读取默认矿石,加载背包的时候更新为正确矿石 */ item->ore_ = oreManager->defaultOre(); equipmentItems_->setObject(item, MCObjectIdToDickKey(o_id)); } /* 读取防具 */ #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) pstrFileContent = CCString::createWithContentsOfFile(kMCEquipmentItemArmorFilepath); if (pstrFileContent) { armor.loadFromString(pstrFileContent->getCString()); } #else armor.loadFromFile(CCFileUtils::sharedFileUtils()->fullPathForFilename(kMCEquipmentItemArmorFilepath).c_str()); #endif root = armor.getObject(); for (rootIterator = root.begin(); rootIterator != root.end(); ++rootIterator) { const char *c_str_o_id = rootIterator->first.c_str(); JsonBox::Object object = rootIterator->second.getObject(); mc_object_id_t o_id = { c_str_o_id[0], c_str_o_id[1], c_str_o_id[2], c_str_o_id[3] }; MCEquipmentItem *item = MCEquipmentItem::create(MCEquipment::MCArmor); CCString *ccstring; item->setID(o_id); ccstring = CCString::create(object["name"].getString().c_str()); item->setName(ccstring); ccstring->retain(); ccstring = CCString::create(object["description"].getString().c_str()); item->setDescription(ccstring); ccstring->retain(); ccstring = CCString::create(object["icon"].getString().c_str()); item->setIcon(ccstring); ccstring->retain(); item->setPrice(object["price"].getInt()); MCArmor *equipment = dynamic_cast<MCArmor *>(item->equipment_); equipment->defense = object["defense"].getInt(); equipment->dexterity = object["dexterity"].getInt(); equipment->armorCheckPenalty = object["armor-check-penalty"].getInt(); /* 读取默认矿石,加载背包的时候更新为正确矿石 */ item->ore_ = oreManager->defaultOre(); equipmentItems_->setObject(item, MCObjectIdToDickKey(o_id)); } }
void GameLayer::initPlayer() { CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); frameCache->addSpriteFramesWithFile("LuckyFlying.plist"); CCSpriteBatchNode* pigeonFlightSheet = CCSpriteBatchNode::create("LuckyFlying.png"); addChild(pigeonFlightSheet, 3); CCArray* pigeonFrames = new CCArray; for ( int i = 2; i <= 4; i++) { CCString* filename = CCString::createWithFormat("lucky_flying_0000%d.png", i); CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(filename->getCString()); pigeonFrames->addObject(frame); } CCAnimation* flightAnim = CCAnimation::createWithSpriteFrames(pigeonFrames, 0.1); pigeonSprite = CCSprite::createWithSpriteFrameName("lucky_flying_00002.png"); //pigeonSprite->setScale(0.5f); pigeonSprite->setPosition(ccp(SCREEN_WIDTH/2 - 500, SCREEN_WIDTH*3 + 250)); CCAction* flightAction = CCRepeatForever::create(CCAnimate::create(flightAnim)); pigeonSprite->runAction(flightAction); pigeonFlightSheet->addChild(pigeonSprite, 3); schedule(schedule_selector(GameLayer::tick1), 0.10f); schedule(schedule_selector(GameLayer::tick2), 0.03f); }
void ChooseMap::getArray(CCObject* obj){ CCString *para = static_cast<CCString*>(obj); s = para->getCString(); }
bool WinPointsUseCommand::handleRecieve(cocos2d::CCDictionary *dict) { if (dict->valueForKey("cmd")->compare(WIN_POINTS_USE) != 0) return false; CCDictionary *params=_dict(dict->objectForKey("params")); if (!params) { return false; } const CCString *pStr = params->valueForKey("errorCode"); if (pStr->compare("")!=0) { CCCommonUtils::flyText((_lang(pStr->getCString()).c_str())); }else{ int itemId = params->valueForKey("itemId")->intValue(); if (params->objectForKey("remainPoints")) { long remainPoints = params->valueForKey("remainPoints")->doubleValue(); GlobalData::shared()->playerInfo.winPoint = remainPoints; } if(params && params->objectForKey("itemEffectObj")) { auto effectObj = _dict(params->objectForKey("itemEffectObj")); if (effectObj->objectForKey("oldStatus")) {//删除该状态的作用 int reStatusId = effectObj->valueForKey("oldStatus")->intValue(); if (GlobalData::shared()->statusMap.find(reStatusId) != GlobalData::shared()->statusMap.end()) { GlobalData::shared()->statusMap[reStatusId] = 0; } } if (effectObj->objectForKey("effectState")) { auto stateDict = _dict(effectObj->objectForKey("effectState")); CCDictElement* element; CCDICT_FOREACH(stateDict, element) { string key = element->getStrKey(); int effectId = atoi(key.c_str()); if(effectId>=PLAYER_PROTECTED_TIME1 && effectId<=PLAYER_PROTECTED_TIME5){ GlobalData::shared()->playerInfo.protectTimeStamp = stateDict->valueForKey(key)->doubleValue(); if(SceneController::getInstance()->currentSceneId == SCENE_ID_WORLD){ WorldMapView::instance()->m_map->updateDynamicMap(WorldController::getInstance()->selfPoint); } } 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())] = time; } auto info = ToolController::getInstance()->getToolInfoById(itemId); map<int, CCDictionary* >::iterator it = ToolController::getInstance()->m_statusItems.find(info.type2); CCObject* obj = element->getObject(); CCString* str = (CCString*)obj; if(info.type==4){ 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[info.type2] = 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[info.type2] = infoDic; } } if (effectObj->objectForKey("status")) { auto arr = dynamic_cast<CCArray*>(effectObj->objectForKey("status")); if (arr) { CCDictionary *item = NULL; for (int i=0; i<arr->count(); i++) { item = _dict(arr->objectAtIndex(i)); auto effState = stateEffect(); effState.effectId = item->valueForKey("effNum")->intValue(); effState.value = item->valueForKey("effVal")->intValue(); effState.stateId = item->valueForKey("stateId")->intValue(); if (GlobalData::shared()->effectStateMap.find(effState.effectId) != GlobalData::shared()->effectStateMap.end()) {//去除重复的stateId vector<stateEffect>::iterator it = GlobalData::shared()->effectStateMap[effState.effectId].begin(); for (; it != GlobalData::shared()->effectStateMap[effState.effectId].end(); it++) { if (effState.stateId == it->stateId) { GlobalData::shared()->effectStateMap[effState.effectId].erase(it); break; } } } GlobalData::shared()->effectStateMap[effState.effectId].push_back(effState); } } } } }
bool Fish::init(FishType type) { _type = type; CCString* animationName = CCString::createWithFormat(STATIC_DATA_STRING("fish_animation"), _type); CCAnimation* fishAnimation = CCAnimationCache::sharedAnimationCache()->animationByName(animationName->getCString()); CCAnimate* fishAnimate = CCAnimate::create(fishAnimation); fishAnimate->setTag(k_Action_Animate); _fishSprite = CCSprite::create(); this->addChild(_fishSprite); _fishSprite->runAction(CCRepeatForever::create(fishAnimate)); return true; }
bool CMainSelect::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } this->setTouchEnabled(true); // 创建背景 CCSize size = CCDirector::sharedDirector()->getWinSize(); CCSprite* backgroud = CCSprite::create("mainsel/bg.png"); backgroud->setPosition( ccp(size.width/2, size.height/2) ); this->addChild(backgroud); // 按钮 CCMenuItemImage *pLack = CCMenuItemImage::create("mainsel/lackNor.png", "mainsel/lackSel.png", this, menu_selector(CMainSelect::lakeCallback) ); CCMenuItemImage *pForest = CCMenuItemImage::create("mainsel/forestNor.png", "mainsel/forestSel.png", this, menu_selector(CMainSelect::forestCallback) ); CCMenuItemImage *pDesert = CCMenuItemImage::create("mainsel/desertNor.png", "mainsel/desertSel.png", this, menu_selector(CMainSelect::desertCallback) ); CCMenuItemImage *pPrairie = CCMenuItemImage::create("mainsel/prairieNor.png", "mainsel/prairieSel.png", this, menu_selector(CMainSelect::prairieCallback) ); pLack->setPosition( ccp(171, 437) ); pForest->setPosition( ccp(539, 401) ); pDesert->setPosition( ccp(864, 411) ); pPrairie->setPosition( ccp(392, 208) ); CCMenu* pMenu = CCMenu::create(pLack, pForest, pDesert, pPrairie, NULL); pMenu->setPosition( CCPointZero ); this->addChild(pMenu, 1); // 创建sprite sheet CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("mainsel/jingyu.plist"); CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::create("mainsel/jingyu.png"); this->addChild(spriteSheet); // 创建对象 CCSprite *sprite = CCSprite::createWithSpriteFrameName("jingyu01.png"); sprite->setPosition(ccp(920,220)); spriteSheet->addChild(sprite, 0); CCArray *arrShang = CCArray::create(); // 动画帧数组 for(int i=1; i<=8; ++i) { CCString *name = CCString::createWithFormat("jingyu%02d.png", i); arrShang->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString())); } CCArray *arrPeng = CCArray::create(); // 动画帧数组 for(int i=9; i<=11; ++i) { CCString *name = CCString::createWithFormat("jingyu%02d.png", i); arrPeng->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString())); } CCArray *arrPengRev = CCArray::createWithArray(arrPeng); arrPengRev->reverseObjects(); arrPeng->addObjectsFromArray(arrPengRev); CCFiniteTimeAction *delay = CCDelayTime::create(1); CCAnimate* anShang = CCAnimate::create(CCAnimation::createWithSpriteFrames(arrShang, 0.25)); CCAnimate* anPeng = CCAnimate::create(CCAnimation::createWithSpriteFrames(arrPeng, 0.15)); sprite->runAction(CCRepeatForever::create((CCActionInterval*)CCSequence::create(anShang, delay, anPeng,anPeng, anPeng, anPeng, anPeng, anShang->reverse(),delay,delay,delay,NULL))); return true; }
configHeroItem* CData::getConfigOfHero(int tempid) { if(m_config_hero_dic->count() < 1) { // const char * path=CCFileUtils::sharedFileUtils()->fullPathForFilename("hero.json").c_str(); // ifstream ifs; // ifs.open(path); // assert(ifs.is_open()); Json::Reader reader; Json::Value root; Json::Value items; Json::Value::Members members; // Json::Value::iterator it; Json::Value::Members::iterator it; string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("hero.json"); CCString* str = CCString::createWithContentsOfFile(path.c_str()); if(reader.parse(str->getCString(), root)){ members = root.getMemberNames(); it = members.begin(); while (it != members.end()) { items = root[std::string(*it)]; configHeroItem * item= new configHeroItem(); char inttostr[20]=""; sprintf(inttostr, "%d",tempid); item->DexGrowth = items["DexGrowth"].asInt();//" : 970, item->StrGrowth = items["StrGrowth"].asInt();//" : 2925, item->VitGrowth = items["VitGrowth"].asInt();//" : 2100, item->WisGrowth = items["WisGrowth"].asInt();//" : 1026, item->attrType = items["attrType"].asInt();//" : 3, item->baseQuality = items["baseQuality"].asInt();//" : 5, item->coin = items["coin"].asInt();//" : 50000, item->descript = items["descript"].asString();//" : "会释放邪恶法术的士兵,攻击力较高防御较低,擅长远程群体攻击。", item->icon = items["icon"].asInt();//" : 378, item->id = items["id"].asInt();// : 35107, item->level = items["level"].asInt();//" : 103, item->nickname = items["nickname"].asString();//" : "蛮夷邪士", item->ordSkill = items["ordSkill"].asInt();//" : 5107, item->resourceid = items["resourceid"].asInt();//" : 5107, item->skill = items["skill"].asInt();//" : 710303, item->soulcount = items["soulcount"].asInt();//" : 100, item->soulrequired = items["soulrequired"].asInt();//" : 41004094, item->type = items["type"].asInt();//" : 220000, item->xy = items["xy"].asInt();//" : -1 m_config_hero_dic->setObject(item, item->id); // item->bodytype=items["bodyType"].asInt(); // item->name=items["name"].asString(); // item->pinzhi=items["baseQuality"].asInt(); // item->des=items["description"].asString(); // item->tempid = items["id"].asInt(); // item->bodytype = items["bodytype"].asInt(); // // m_config_goods_dic->setObject(item, item->tempid); it++; } // ifs.close(); } } return (configHeroItem*)m_config_hero_dic->objectForKey(tempid); }
void Runner::initAction() { //init runningAction CCArray *animFrames = CCArray::create(); for (int i = 0; i < 8; i++) { CCString* name = CCString::createWithFormat("runner%d.png",i); CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString()); animFrames->addObject(frame); } CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.1); m_actionRunning =CCRepeatForever::create(CCAnimate::create(animation)); m_actionRunning->retain(); // init jumpUpAction animFrames = CCArray::create(); for (int i=0; i<4; i++) { CCString* name = CCString::createWithFormat("runnerJumpUp%d.png",i); CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString()); animFrames->addObject(frame); } animation = CCAnimation::createWithSpriteFrames(animFrames, 0.2); m_actionJumpUp = CCAnimate::create(animation); m_actionJumpUp->retain(); // init jumpDownAction animFrames->removeAllObjects(); for (int i=0; i<2; i++) { CCString *name = CCString::createWithFormat("runnerJumpDown%d.png",i); CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString()); animFrames->addObject(frame); } animation = CCAnimation::createWithSpriteFrames(animFrames, 0.3); m_actionJumpDown = CCAnimate::create(animation); m_actionJumpDown->retain(); // init crouchAction animFrames->removeAllObjects(); for (int i=0; i<1; i++) { CCString *name = CCString::createWithFormat("runnerCrouch%d.png",i); CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString()); animFrames->addObject(frame); } animation = CCAnimation::createWithSpriteFrames(animFrames, 0.3); m_actionCrouch = CCAnimate::create(animation); m_actionCrouch->retain(); }
bool GAFAsset::initWithImageData(const std::string& jsonPath) { GAFData aConfigData; std::string fp = CCFileUtils::sharedFileUtils()->fullPathForFilename(jsonPath.c_str()); aConfigData.delete_data = true; aConfigData.ptr = CCFileUtils::sharedFileUtils()->getFileData(fp.c_str(), "rb", &aConfigData.size); if (!aConfigData.ptr) { CCLOGERROR("Can not get data from json file : %s", jsonPath.c_str()); return NULL; } if (!aConfigData.getBytes()) { CCLOGWARN("can not init GAFAsset - invalid anImageData"); return false; } CCDictionary* configDictionary = CCJSONConverter::sharedConverter()->dictionaryFrom( (const char *)aConfigData.getBytes()); CCString *versionNode = (CCString*)configDictionary->objectForKey(kVersionKey); if (!isAssetVersionPlayable(versionNode->getCString())) { return false; } CCArray *animationConfigFrames = (CCArray *)configDictionary->objectForKey(kAnimationConfigFramesKey); CCArray *interactionObjectNodes = (CCArray *)configDictionary->objectForKey(kInteractionObjectsKey); CCArray *standObjectsNodes = (CCArray *)configDictionary->objectForKey(kStandObjectsKey); CCArray *textureAtlasNode = (CCArray *)configDictionary->objectForKey(kTextureAtlasKey); CCArray *animationSequences = (CCArray *)configDictionary->objectForKey(kAnimationSequencesKey); CCDictionary *objectNodes = (CCDictionary *)configDictionary->objectForKey(kAnimationObjectsKey); CCDictionary *masksNodes = (CCDictionary *)configDictionary->objectForKey(kAnimationMasksKey); CCDictionary *namedPartsNodes = (CCDictionary *)configDictionary->objectForKey(kAnimationNamedPartsKey); if (!animationConfigFrames || !textureAtlasNode|| !objectNodes) { CCLOGERROR("Error while creating GAFAsset. Required subnodes in dictionary are missing."); return false; } CC_SAFE_RELEASE(_textureAtlas); if (!textureAtlasNode->count()) { return false; } CCDictionary * atlasDictionary = (CCDictionary *)textureAtlasNode->objectAtIndex(0); float atlasScale = atlasScaleFromAtlasConfig(atlasDictionary); for (int i = 1; i < textureAtlasNode->count(); ++i) { CCDictionary * a = (CCDictionary *)textureAtlasNode->objectAtIndex(i); float as = atlasScaleFromAtlasConfig(a); if ( fabs(atlasScale - _currentDeviceScale) > fabs(as - _currentDeviceScale)) { atlasDictionary = a; atlasScale = as; } } _usedAtlasContentScaleFactor = atlasScale; CCArray * atlasesInfo = (CCArray *)atlasDictionary->objectForKey(kAtlasInfoKey); if (!atlasesInfo) { CCLOGERROR("Error while creating GAFAsset.atlasesInfo subnode is missing in atlasDictionary."); return false; } _textureAtlas = GAFTextureAtlas::create(fp.c_str(), atlasDictionary); if (!_textureAtlas) { CCLOGERROR("Failed to initialize GAFAsset. GAFTextureAtlas could not be created."); return false; } CC_SAFE_RETAIN(_textureAtlas); if (_objects != objectNodes) { CC_SAFE_RELEASE(_objects); _objects = objectNodes; CC_SAFE_RETAIN(_objects); } if (_masks != masksNodes) { CC_SAFE_RELEASE(_masks); _masks = masksNodes; CC_SAFE_RETAIN(_masks); } if (_namedParts != namedPartsNodes) { CC_SAFE_RELEASE(_namedParts); _namedParts = namedPartsNodes; CC_SAFE_RETAIN(_namedParts); } if (interactionObjectNodes) { CC_SAFE_RELEASE(_interactionObjects); _interactionObjects = CCArray::create(); CC_SAFE_RETAIN(_interactionObjects); for (int i = 0; i < interactionObjectNodes->count(); ++i) { CCDictionary * dict = (CCDictionary*)interactionObjectNodes->objectAtIndex(i); GAFInteractionObject * interObject = GAFInteractionObject::create(dict); if (interObject) { _interactionObjects->addObject(interObject); } } } if (standObjectsNodes) { CC_SAFE_RELEASE(_standObjects); _standObjects = CCArray::create(); CC_SAFE_RETAIN(_standObjects); for (int i = 0; i < standObjectsNodes->count(); ++i) { CCDictionary * dict = (CCDictionary*)standObjectsNodes->objectAtIndex(i); GAFActionObject * interObject = GAFActionObject::create(dict); if (interObject) { _standObjects->addObject(interObject); } } } loadFramesFromConfigDictionary(configDictionary); if (animationSequences) { loadAnimationSequences(animationSequences); } return true; }
void AnimationManager::preLoadAnimations() { CCAnimation* pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_idle"); if (pAnimation == NULL) { pAnimation = CCAnimation::create(); for (int i=0; i<4; i++) { CCString* pFileName = CCString::createWithFormat("idle/o%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.2f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_idle"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_run"); if (pAnimation == NULL) { pAnimation = CCAnimation::create(); for (int i=0; i<4; i++) { CCString* pFileName = CCString::createWithFormat("run/m%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_run"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_atk_a"); if (pAnimation == NULL) { int iKeyFrame = 4; pAnimation = CCAnimation::create(); for (int i=1; i<=4; i++) { CCString* pFileName = CCString::createWithFormat("skill/a%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); if (i == iKeyFrame) { for (int k=0; k<2; k++) { pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } } } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_atk_a"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_atk_b"); if (pAnimation == NULL) { int iKeyFrame = 2; pAnimation = CCAnimation::create(); for (int i=1; i<=4; i++) { CCString* pFileName = CCString::createWithFormat("skill/b%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); if (i == iKeyFrame) { for (int k=0; k<2; k++) { pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } } } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_atk_b"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_atk_c"); if (pAnimation == NULL) { int iKeyFrame = 3; pAnimation = CCAnimation::create(); for (int i=1; i<=4; i++) { CCString* pFileName = CCString::createWithFormat("skill/c%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); if (i == iKeyFrame) { for (int k=0; k<2; k++) { pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } } } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_atk_c"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_atk_d"); if (pAnimation == NULL) { int iKeyFrame = 4; pAnimation = CCAnimation::create(); for (int i=1; i<=4; i++) { CCString* pFileName = CCString::createWithFormat("skill/d%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); if (i == iKeyFrame) { for (int k=0; k<2; k++) { pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } } } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_atk_d"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_atk_e"); if (pAnimation == NULL) { int iKeyFrame = 3; pAnimation = CCAnimation::create(); for (int i=1; i<=4; i++) { CCString* pFileName = CCString::createWithFormat("skill/e%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); if (i == iKeyFrame) { for (int k=0; k<2; k++) { pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } } } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_atk_e"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_atk_f"); if (pAnimation == NULL) { int iKeyFrame = 3; pAnimation = CCAnimation::create(); for (int i=1; i<=4; i++) { CCString* pFileName = CCString::createWithFormat("skill/f%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); if (i == iKeyFrame) { for (int k=0; k<2; k++) { pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } } } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_atk_f"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_atk_g"); if (pAnimation == NULL) { int iKeyFrame = 2; pAnimation = CCAnimation::create(); for (int i=1; i<=4; i++) { CCString* pFileName = CCString::createWithFormat("skill/g%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); if (i == iKeyFrame) { for (int k=0; k<2; k++) { pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } } } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_atk_g"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_atk_h"); if (pAnimation == NULL) { int iKeyFrame = 3; pAnimation = CCAnimation::create(); for (int i=1; i<=4; i++) { CCString* pFileName = CCString::createWithFormat("skill/h%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); if (i == iKeyFrame) { for (int k=0; k<2; k++) { pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } } } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_atk_h"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_atk_i"); if (pAnimation == NULL) { int iKeyFrame = 4; pAnimation = CCAnimation::create(); for (int i=1; i<=4; i++) { CCString* pFileName = CCString::createWithFormat("skill/i%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); if (i == iKeyFrame) { for (int k=0; k<2; k++) { pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } } } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_atk_i"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_atk_j"); if (pAnimation == NULL) { int iKeyFrame1 = 2; int iKeyFrame2 = 5; pAnimation = CCAnimation::create(); for (int i=1; i<=8; i++) { CCString* pFileName = CCString::createWithFormat("skill/j%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); if (i==iKeyFrame1 || i==iKeyFrame2) { for (int k=0; k<2; k++) { pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } } } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_atk_j"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_behit_0"); if (pAnimation == NULL) { pAnimation = CCAnimation::create(); for (int i=1; i<=3; i++) { CCString* pFileName = CCString::createWithFormat("behit/n%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_behit_0"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_behit_1"); if (pAnimation == NULL) { pAnimation = CCAnimation::create(); for (int i=1; i<=5; i++) { CCString* pFileName = CCString::createWithFormat("behit/n%04d.png", 1); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } //补偿动画 for (int i=0; i<=6; i++) { CCString* pFileName = CCString::createWithFormat("behit/r%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_behit_1"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_dead"); if (pAnimation == NULL) { pAnimation = CCAnimation::create(); for (int i=0; i<5; i++) { CCString* pFileName = CCString::createWithFormat("dead/s%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_dead"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("hero_win"); if (pAnimation == NULL) { pAnimation = CCAnimation::create(); for (int i=1; i<=3; i++) { CCString* pFileName = CCString::createWithFormat("win/1%04d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "hero_win"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("atk_bg"); if (pAnimation == NULL) { pAnimation = CCAnimation::create(); for (int i=1; i<=3; i++) { CCString* pFileName = CCString::createWithFormat("1%03d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "atk_bg"); } pAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("atk_ko"); if (pAnimation == NULL) { pAnimation = CCAnimation::create(); for (int i=1; i<30; i++) { CCString* pFileName = CCString::createWithFormat("3%03d.png", i); pAnimation->addSpriteFrameWithFileName(pFileName->getCString()); } pAnimation->setRestoreOriginalFrame(true); pAnimation->setDelayPerUnit(0.1f); // 必须设置这个,要不就不会播放 pAnimation->setLoops(1); CCAnimationCache::sharedAnimationCache()->addAnimation(pAnimation, "atk_ko"); } }
void GameNewLinker::beginDrawLine() { CCPoint first = spritelistNow[first_box] -> getPosition(); CCPoint second = spritelistNow[sencond_box] -> getPosition(); float x = first.x - second.x; float y = first.y - second.y; CCPoint point; bool wellDraw = false; if (sencond_box - first_box == 1 || sencond_box - first_box == -1) { wellDraw = true; } int length = list.size() == 25 ? 5 :6; if (sencond_box - first_box == length || sencond_box -first_box == (-1*length)) { wellDraw = true; } if (!wellDraw) { isCanDrawLine = false; return; } //判断线的方向 if (x < 0 && y == 0) { point = CCPoint(spritelistNow[first_box] -> getPositionX()+spritelistNow[first_box]->getContentSize().width*size, spritelistNow[first_box] -> getPositionY() + spritelistNow[first_box]->getContentSize().height /2*size); } if (x > 0 && y == 0) { point = CCPoint(spritelistNow[first_box] -> getPositionX(), spritelistNow[first_box] -> getPositionY() + spritelistNow[first_box] -> getContentSize().height /2*size); } if (x == 0 && y < 0) { point = CCPoint(spritelistNow[first_box] -> getPositionX()+spritelistNow[first_box]->getContentSize().width/2*size, spritelistNow[first_box] -> getPositionY() + spritelistNow[first_box]->getContentSize().height*size); } if (x == 0 && y > 0) { point = CCPoint(spritelistNow[first_box] -> getPositionX()+spritelistNow[first_box]->getContentSize().width/2*size, spritelistNow[first_box] -> getPositionY()); } //将所有线条设置为显示 for (int i = 0; i < linelist.size(); i ++) { linelist[i].pic -> setVisible(true); } for (int i = 0; i < linelist.size(); i++) { vector<lineTiem>linelist1; if (linelist[i].kind == LineKind) { int end = linelist[i].endIndex; for (int j = 0; j < linelist.size(); j ++) { linelist1.clear(); if (linelist[j].endIndex == end && linelist[j].kind != LineKind) { for (int m = 0; m < linelist.size(); m ++) { if (linelist[m].kind == linelist[j].kind) { linelist1.push_back(linelist[m]); } } for (int n = 0; n < linelist1.size(); n ++) { if (linelist1[n].endIndex == end) { lineTiem a = linelist1[n]; a.pic -> setVisible(false); while (1) { for (int k = 0; k < linelist1.size(); k++) { if (linelist1[k].beginIndex == end) { linelist1[k].pic -> setVisible(false); end = linelist1[k].endIndex; continue; } } break; } } } } } } } //按照条件设置部分线条为隐藏 for (int i = 0; i < linelist.size(); i ++) { //回滚原来的线条,会删除图片 if (linelist[i].beginIndex == sencond_box && linelist[i].endIndex == first_box && LineKind == linelist[i].kind) { vector<lineTiem>linelist1; for (int j = 0 ; j < linelist.size(); j ++) { if (linelist[j].beginIndex == linelist[i].beginIndex && linelist[j].endIndex == linelist[i].endIndex) { continue; } else linelist1.push_back(linelist[j]); } linelist[i].pic -> removeFromParentAndCleanup(true); linelist.clear(); linelist = linelist1; linelist1.clear(); first_box = sencond_box; return; } //不同颜色尾部相交 if (linelist[i].endIndex == sencond_box && LineKind != linelist[i].kind) { lineTiem model = linelist[i]; model.pic -> setVisible(false); int next = model.endIndex; while (1) { for (int j = 0; j < linelist.size(); j ++) { if (linelist[j].beginIndex == next && linelist[j].kind == linelist[i].kind) { linelist[j].pic -> setVisible(false); next = linelist[j].endIndex; continue; } } break; } } } CCString str; int t = drawLineKind; if (LineKind == StarIcon) { t = 4; } if (LineKind == Box_5w) { t = 5; } str.initWithFormat("line/link_line_%d.png", t); auto line = CCSprite::createWithSpriteFrameName(str.getCString()); if (x == 0 && y < 0) { line -> setRotation(90); } if (x == 0 && y > 0) { line -> setRotation(90); } line -> setScaleY(0.8*size); line -> setScaleX(0.9*size); line -> setPosition(point); CCString str1; lineTiem item; item.pic = line; item.kind = LineKind; item.beginIndex = first_box; item.endIndex = sencond_box; item.haveNext = false; item.drawKind = drawLineKind; for (int i = 0; i < linelist.size(); i ++) { if (linelist[i].kind == LineKind && !linelist[i].haveNext) { linelist[i].haveNext = true; } } linelist.push_back(item); lineNode -> addChild(line); first_box = sencond_box; showSharder(); }
bool GameButton::initWithText(const char * text, bool isBig) { if (!CCSprite::init()) { return false; } CCString* btnFrame = (isBig) ? CCString::create("button_big.png") : CCString::create("button_small.png"); int fSize = 18 * Utils::getArtScaleFactor(); this->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(btnFrame->getCString())); CCLabelTTF *label = CCLabelTTF::create(text, CCString::createWithFormat("%s.ttf",FONT_MAIN)->getCString(), fSize + isBig * fSize); label->setPosition(ccp(this->getContentSize().width/2,this->getContentSize().height/2)); this->addChild(label,1); CCLabelTTF *labelShadow = CCLabelTTF::create(text, CCString::createWithFormat("%s.ttf",FONT_MAIN)->getCString(), fSize + isBig * fSize); labelShadow->setPosition(ccp(this->getContentSize().width/2 - (2 + isBig * 2),this->getContentSize().height/2)); labelShadow->setColor(ccBLACK); labelShadow->setOpacity(150); this->addChild(labelShadow,0); this->setScale(Utils::getScale()); return true; }
void RPGMapItemsMenuLayer::onButton(cocos2d::CCObject *pSender, CCControlEvent event) { SimpleAudioEngine::sharedEngine()->playEffect("audio_effect_btn.wav"); CCControlButton *itemBtn = (CCControlButton*)pSender; if(itemBtn->getTag() == kRPGMapItemsMenuLayerTagBtnDiscard) { // CCLog("丢弃道具"); RPGResultsLogic::discardItems(this->m_db, this->m_selectedItems->m_dataId); this->getParent()->removeChildByTag(kRPGMapSceneLayerTagChoicePlayerMenuLayerBg, true); this->getParent()->removeChildByTag(kRPGMapSceneLayerTagChoicePlayerMenuLayer, true); this->getParent()->removeChildByTag(kRPGMapItemsMenuLayerTagBtnDiscard, true); this->setVisible(true); this->loadItemsData(); } else { for (int i = 0; i < this->m_itemsList->count(); i++) { //判断选中道具 RPGExistingItems *itemsData = (RPGExistingItems*)this->m_itemsList->objectAtIndex(i); if(itemBtn->getTag() == itemsData->m_dataId) { this->m_selectedItems = itemsData; break; } } //因为动态获取地图的大小会导致了菜单层显示错位,所以定死了 float width = 960; float height = 640; //临时背景 CCTMXTiledMap *mainBg = CCTMXTiledMap::create(CCString::createWithFormat("map_menu3_%s.tmx", CCUserDefault::sharedUserDefault()->getStringForKey(GAME_STYLE).c_str())->getCString()); mainBg->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width / 2, CCDirector::sharedDirector()->getWinSize().height / 2)); mainBg->setAnchorPoint(ccp(0.5, 0.5)); mainBg->setTag(kRPGMapSceneLayerTagChoicePlayerMenuLayerBg); this->getParent()->addChild(mainBg); CCString *title = CCString::createWithFormat(((CCString*)this->m_stringList->objectForKey("menu_items_choice"))->getCString(), this->m_selectedItems->m_name.c_str()); RPGMapChoicePlayerMenuLayer *choicePlayer = RPGMapChoicePlayerMenuLayer::create(this->m_db, title, this, callfuncO_selector(RPGMapItemsMenuLayer::onChoicePlayer), width, height); choicePlayer->setTag(kRPGMapSceneLayerTagChoicePlayerMenuLayer); this->getParent()->addChild(choicePlayer); if(this->m_selectedItems->m_type != 3) { // CCLog("非道具不可以使用"); choicePlayer->setHidden(true); } CCString *btnDiscardText = CCString::createWithFormat(((CCString*)this->m_stringList->objectForKey("menu_items_discard"))->getCString(), this->m_selectedItems->m_name.c_str()); CCControlButton *btnDiscard = CCControlButton::create(btnDiscardText->getCString(), "Arial", 24); btnDiscard->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width / 2, 250)); btnDiscard->setTag(kRPGMapItemsMenuLayerTagBtnDiscard); btnDiscard->addTargetWithActionForControlEvents(this, cccontrol_selector(RPGMapItemsMenuLayer::onButton), CCControlEventTouchUpInside); this->getParent()->addChild(btnDiscard); this->setVisible(false); } }
void MCItemManager::loadEffectiveItems() { JsonBox::Value v; JsonBox::Object root; JsonBox::Object::iterator rootIterator; MCEffectiveItem *item; MCEffectManager *effectManager = MCEffectManager::sharedEffectManager(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) CCString* pstrFileContent = CCString::createWithContentsOfFile(kMCEffectiveItemFilepath); if (pstrFileContent) { v.loadFromString(pstrFileContent->getCString()); } #else v.loadFromFile(CCFileUtils::sharedFileUtils()->fullPathForFilename(kMCEffectiveItemFilepath).c_str()); #endif root = v.getObject(); for (rootIterator = root.begin(); rootIterator != root.end(); ++rootIterator) { const char *c_str_o_id = rootIterator->first.c_str(); JsonBox::Object object = rootIterator->second.getObject(); mc_object_id_t o_id = { c_str_o_id[0], c_str_o_id[1], c_str_o_id[2], c_str_o_id[3] }; if (o_id.class_ == 'P') { item = MCEffectiveItem::create(); } else { MCTrap *trap = new MCTrap; trap->init(o_id); trap->autorelease(); item = trap; } CCString *ccstring; item->setID(o_id); ccstring = CCString::create(object["name"].getString().c_str()); item->setName(ccstring); ccstring->retain(); ccstring = CCString::create(object["description"].getString().c_str()); item->setDescription(ccstring); ccstring->retain(); ccstring = CCString::create(object["icon"].getString().c_str()); item->setIcon(ccstring); ccstring->retain(); /* effect-id */ c_str_o_id = object["effect-id"].getString().c_str(); mc_object_id_t e_id = { c_str_o_id[0], c_str_o_id[1], c_str_o_id[2], c_str_o_id[3] }; MCEffect *effect = effectManager->effectForObjectId(e_id); item->effect = effect; effect->retain(); item->setPrice(object["price"].getInt()); item->radius = object["radius"].getInt() * 24 / CC_CONTENT_SCALE_FACTOR(); /* 24为一个单位 */ item->hp = object["hp"].getInt(); item->pp = object["pp"].getInt(); item->positive_state = object["positive-state"].getInt(); item->lasting_time = object["lasting-time"].isDouble() ? (float) object["lasting-time"].getDouble() : (float) object["lasting-time"].getInt(); effectiveItems_->setObject(item, MCObjectIdToDickKey(o_id)); } }
void GameLayer_GoldMarket::sureBuyCallEffect(int i,int iType){ CCPoint point; switch (i) { case 1: point.x =105; point.y =725; break; case 2: point.x =105; point.y =625; break; case 3: point.x =105; point.y =525; break; case 4: point.x =105; point.y =425; break; case 5: point.x =105; point.y =325; break; default: break; } CCSize visableSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint goldPosition = ccp(visableSize.width/2-60,visableSize.height-45); char str1[100]={0}; switch(iType) { case 1: sprintf(str1,"./CocoStudioResources/DayLogin/WhiteGold.png"); break; case 2: sprintf(str1,"./CocoStudioResources/DayLogin/WhiteJewel.png"); default: break; } char str2[100]={0}; switch(iType) { case 1: sprintf(str2,"./CocoStudioResources/DayLogin/Star1.png"); break; case 2: sprintf(str2,"./CocoStudioResources/DayLogin/jewelStar1.png"); break; default: break; } char str3[100]={0}; switch(iType) { case 1: sprintf(str3,"./CocoStudioResources/DayLogin/FlyGold.png"); break; case 2: sprintf(str3,"./CocoStudioResources/DayLogin/FlyJewel.png"); break; default: break; } //最后亮一下的金币. CCSprite* lightGold1 = CCSprite::create(str1); this->addChild(lightGold1,10); lightGold1->setPosition(goldPosition); lightGold1->setVisible(false); CCSequence* lightGoldAction1 = CCSequence::create(CCShow::create() ,CCFadeOut::create(0.5),NULL); CCSprite* lightGold2 = CCSprite::create(str1); this->addChild(lightGold2,10); lightGold2->setPosition(goldPosition); lightGold2->setVisible(false); CCSequence* lightGoldAction2 = CCSequence::create(CCShow::create() ,CCFadeOut::create(0.5),NULL); CCSprite* lightGold3 = CCSprite::create(str1); this->addChild(lightGold3,10); lightGold3->setVisible(false); CCSequence* lightGoldAction3 = CCSequence::create(CCShow::create() ,CCFadeOut::create(0.5),NULL); lightGold3->setPosition(goldPosition); //钱的闪光. CCString str; CCAnimation* pAni = CCAnimation::create(); for (int i=1; i<=3; i++) { if (iType==1) str.initWithFormat("./CocoStudioResources/DayLogin/Star%d.png",i); else if(iType==2) str.initWithFormat("./CocoStudioResources/DayLogin/jewelStar%d.png",i); pAni->addSpriteFrameWithFileName(str.getCString()); } pAni->setDelayPerUnit(0.3f/3.f); pAni->setLoops(1); //金币爆炸效果. CCSprite* goldEffect1 = CCSprite::create(); goldEffect1->setVisible(false); auto *pic_1 = CCSprite::create(str2); goldEffect1->setTexture(pic_1 -> getTexture()); goldEffect1->setTextureRect(CCRectMake(0, 0, pic_1 -> getContentSize().width, pic_1 -> getContentSize().height)); goldEffect1->setPosition(ccp(visableSize.width/2,visableSize.height-50)); CCSequence* goldAction1 = CCSequence::create(CCShow::create(), CCAnimate::create(pAni), CCHide::create(), NULL); this->addChild(goldEffect1, 10); CCSprite* goldEffect2 = CCSprite::create(); goldEffect2->setVisible(false); auto *pic_2 = CCSprite::create(str2); goldEffect2->setTexture(pic_2 -> getTexture()); goldEffect2 -> setTextureRect(CCRectMake(0, 0, pic_2-> getContentSize().width, pic_2->getContentSize().height)); goldEffect2->setPosition(ccp(visableSize.width/2,visableSize.height-50)); CCSequence* goldAction2 = CCSequence::create(CCShow::create(), CCAnimate::create(pAni), CCHide::create(), NULL); this->addChild(goldEffect2, 10); CCSprite* goldEffect3 = CCSprite::create(); goldEffect3->setVisible(false); auto *pic_3 = CCSprite::create(str2); goldEffect3->setTexture(pic_3 -> getTexture()); goldEffect3->setTextureRect(CCRectMake(0, 0, pic_3 -> getContentSize().width, pic_3 -> getContentSize().height)); goldEffect3->setPosition(ccp(visableSize.width/2,visableSize.height-50)); //CCSequence* goldAction3 = CCSequence::create(CCShow::create(), CCAnimate::create(pAni), CCHide::create(),CCCallFunc::create(this, callfunc_selector(GameLayer_DayLogin::DoCallBack)) ,CCCallFunc::create(this, callfunc_selector(GameLayer_DayLogin::removeFromParent)), NULL); CCSequence* goldAction3 = CCSequence::create(CCShow::create(), CCAnimate::create(pAni), CCHide::create(), NULL); this->addChild(goldEffect3, 10); //飞行的钱币. CCSprite* flyGold1 = CCSprite::create(str3); flyGold1->setVisible(false); flyGold1->setPosition(point); this->addChild(flyGold1, 10); CCSequence* flyAction1 = CCSequence::create(CCShow::create(), CCMoveTo::create(0.6, goldPosition), CCCallFuncO::create(lightGold3, callfuncO_selector(CCSprite::runAction), lightGoldAction3), CCCallFuncO::create(goldEffect1, callfuncO_selector(CCSprite::runAction), goldAction1), CCHide::create(), NULL); CCSprite* flyGold2 = CCSprite::create(str3); flyGold2->setVisible(false); flyGold2->setScale(0.9); flyGold2->setPosition(point); this->addChild(flyGold2, 10); CCSequence* flyAction2 = CCSequence::create(CCDelayTime::create(0.3), CCShow::create(), CCMoveTo::create(0.6, goldPosition),CCCallFuncO::create(lightGold2, callfuncO_selector(CCSprite::runAction), lightGoldAction2), CCCallFuncO::create(goldEffect2, callfuncO_selector(CCSprite::runAction), goldAction2), CCHide::create(), NULL); CCSprite* flyGold3 = CCSprite::create(str3); flyGold3->setVisible(false); flyGold3->setScale(0.8); flyGold3->setPosition(point); this->addChild(flyGold3, 10); CCSequence* flyAction3 = CCSequence::create(CCDelayTime::create(0.6), CCShow::create(), CCMoveTo::create(0.6, goldPosition), CCCallFuncO::create(goldEffect3, callfuncO_selector(CCSprite::runAction), goldAction3), CCCallFuncO::create(lightGold1, callfuncO_selector(CCSprite::runAction), lightGoldAction1), CCHide::create(), NULL); //爆炸的闪光效果. CCSprite* riceEffect = CCSprite::create(); pAni = CCAnimation::create(); for (int i=1; i<=4; i++) { str.initWithFormat("./CocoStudioResources/DayLogin/Boom%d.png",i); pAni->addSpriteFrameWithFileName(str.getCString()); } pAni->setDelayPerUnit(0.3f/4.f); pAni->setLoops(1); auto *pic_4 = CCSprite::create("./CocoStudioResources/DayLogin/Boom1.png"); riceEffect->setTexture(pic_4 -> getTexture()); riceEffect->setTextureRect(CCRectMake(0, 0, pic_4 -> getContentSize().width, pic_4 -> getContentSize().height)); riceEffect->setPosition(point); this->addChild(riceEffect, 0); riceEffect->runAction(CCSequence::create(CCAnimate::create(pAni),CCHide::create(), CCCallFuncO::create(flyGold1, callfuncO_selector(CCSprite::runAction), flyAction1), CCCallFuncO::create(flyGold2, callfuncO_selector(CCSprite::runAction), flyAction2), CCCallFuncO::create(flyGold3, callfuncO_selector(CCSprite::runAction), flyAction3),NULL)); }
//对敌方阵营随机5个位置进行伤害,总额为主将攻击力的100% void SGHeroSkill7::activateSkill_20006(SGHeroLayer *heroLayer, SGHeroLayer *heroLayer1, float value1, CCPoint point, int skillId) { if (!heroLayer1 || !heroLayer) { return ; } SGBattleMap *opponentBattleMap = heroLayer1->getBattleMap(); if (!opponentBattleMap) { return ; } SGGridBase *grid = opponentBattleMap->myGrids[(int)point.y][(int)point.x]; if (!grid) { return ; } ShiBing * sb = opponentBattleMap->getShiBingWithGrid(grid); if (!sb) { return ; } bool a = !heroLayer->isme; CCString *name = NULL; CCString *name1 = NULL; if (skillId == skill_id_20026 || skillId == skill_id_20027 || skillId == skill_id_20086 || skillId == skill_id_20096) { name = CCString::create("animationFile/yinsi.plist"); name1 = CCString::create("animationFile/yinsi.scml"); }else{ name = CCString::create("animationFile/ll.plist"); name1 = CCString::create("animationFile/ll.scml"); } // CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(name->getCString()); ResourceManager::sharedInstance()->bindTexture(name->getCString(), RES_TYPE_BATTLE_IMAGE, sg_battleLayer); CCSpriterX *fermEffect = CCSpriterX::create(name1->getCString(), true, true); fermEffect->setanimaID(0); fermEffect->setisloop(false); // fermEffect->setPosition(GameConfig::getGridPoint(a ? -((int)point.y + 1) : (int)point.y, a ? mapList - 1 - (int)point.x :(int)point.x)); fermEffect->setPosition(GameConfig::getGridPoint((int)point.y, (int)point.x, a)); fermEffect->play(); if (heroLayer->isme) { heroLayer->addChild(fermEffect, 100); }else{ heroLayer1->addChild(fermEffect, 100); } if (!grid) { return; } bool isDe = false; CCLOG(">>>>>%f",value1); //掉血效果显示,数值是技能攻击的数值 heroLayer->showBattleLabel(value1, "battle/sub_hp_label.png", SB_ADD_AND_SUB_AP_W, SB_ADD_AND_SUB_AP_H, grid->getIndex()); if (grid->getStype() == knormal) { CCLOG("散兵"); isDe = true; } else if (grid->getStype() == kattack) { CCLOG("攻击阵列"); SGAttackList *attackList = opponentBattleMap->getAttackListByGrid(grid); if (attackList) { if (value1 >= attackList->getAp()) { int newValue = attackList->getAp(); attackList->heroSkillSubAp(newValue); CCLOG("被打死"); isDe = true; } else { //显示掉血效果 attackList->heroSkillSubAp(value1); CCLOG("未被打死"); float newValue = attackList->getAp() - value1; attackList->setAp(newValue); //造成伤害,播放音效 if (value1 > 0) { attackList->playEffectWithType(kAttackEffect); } //攻击后血量减少显示 attackList->drawXueTiaoProportion(); attackList->changAPLabel(); CCLOG("val1 = %f, da = %d, max = %d", value1, attackList->damageNum, attackList->getMax_Ap()); } } } else if(grid ->getStype() == kdefend) { if (!sb) { return ; } CCLOG("防御"); if (value1 >= sb->getDef()) { CCLOG("被打死"); isDe = true; } else { CCLOG("未被打死"); sb->setDef(sb->getDef()- value1); } } if (isDe) { int a = (fermEffect->getAnimaTimeLength(0, 0) * ANIMA_TIME_NUM); CCDelayTime *time = CCDelayTime::create(a); CCCallFuncND *call = CCCallFuncND::create(SGSkillManager::shareSkill(), callfuncND_selector(SGSkillManager::sbSkill_20005), (void*)(a* 10000)); sb->runAction(CCSequence::create(time, call, NULL)); } }
void FightScene::checkSkl() { CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) std::vector<std::string>::const_iterator searchPathsIter = CCFileUtils::sharedFileUtils()->getSearchPaths().begin(); std::string root = *searchPathsIter; std::string dirRoot = root.substr(0, root.length() - 1); dirRoot += "\\bone\\*.equip"; WIN32_FIND_DATA FindFileData; size_t size = dirRoot.length(); wchar_t *buffer = new wchar_t[size+1]; memset(buffer,0,sizeof(wchar_t)*(size+1)); MultiByteToWideChar( CP_ACP, 0, dirRoot.c_str(), size, buffer, size * sizeof(wchar_t) ); buffer[size] = 0; // 确保以 '\0' 结尾 equipList->removeAllObjects(); HANDLE hFind = FindFirstFile(buffer, &FindFileData); if(hFind != INVALID_HANDLE_VALUE) { do { if(FindFileData.cFileName[0]=='.') continue; if(!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { char str[MAX_PATH]={0}; WideCharToMultiByte(CP_ACP, 0, FindFileData.cFileName, sizeof(FindFileData.cFileName) + 1, str, MAX_PATH, NULL, NULL); std::string fgg = std::string(str); if(fgg == "AvatarEquip_defultM.equip") { continue; } size_t last = 0; size_t index = fgg.find_first_of(".",last); while (index!=std::string::npos) { std::string fggg = fgg.substr(last,index-last); std::string path = CCBoneSpriteConfig::getBoneUrl() + fggg + ".equip"; std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(path.c_str()); unsigned long size; char* buffer = (char*)CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "rt", &size); Json* root = Json_create(buffer); CC_SAFE_DELETE_ARRAY(buffer); int count = Json_getSize(root); for(int i = 0; i< count; i++) { Json *tmp = Json_getItemAt(root, i); std::string tmpString = tmp->name; if(tmpString == "full") { continue; } std::string ggg = fggg+"+"+tmpString; CCString *ff = CCString::create(ggg); CCLog(ff->getCString()); equipList->addObject(ff); } Json_dispose(root); break; } } } while(FindNextFile(hFind,&FindFileData) != 0); } delete []buffer; FindClose(hFind); #else equipList->removeAllObjects(); CCString *ff = CCString::create("weapon"); equipList->addObject(ff); ff = CCString::create("goldGlory_M"); equipList->addObject(ff); #endif }
GXString::GXString(const CCString& str) :CCString(str.getCString()) {}
void b2ShapeCache::addShapesWithFile(const std::string &plist, b2Vec2 vertexScale, float ptm) { CCDictionary *dict = CCDictionary::createWithContentsOfFile(plist.c_str()); CCAssert(dict != NULL, "Shape-file not found"); CCAssert(dict->count() != 0, "plist file empty or not existing"); CCDictionary *metadataDict = (CCDictionary *)dict->objectForKey("metadata"); int format = metadataDict->valueForKey("format")->intValue(); ptmRatio = metadataDict->valueForKey("ptm_ratio")->floatValue(); if (ptm <= 0) ptm = ptmRatio; CCLOG("ptmRatio = %f",ptmRatio); CCAssert(format == 1, "Format not supported"); CCDictionary *bodyDict = (CCDictionary *)dict->objectForKey("bodies"); b2Vec2 vertices[b2_maxPolygonVertices]; CCDictElement *dictElem; std::string bodyName; CCDictionary *bodyData; //iterate body list CCDICT_FOREACH(bodyDict,dictElem ) { bodyData = (CCDictionary*)dictElem->getObject(); bodyName = dictElem->getStrKey(); BodyDef *bodyDef = new BodyDef(); CCPoint a = CCPointFromString(bodyData->valueForKey("anchorpoint")->getCString()); float32 ax = (vertexScale.x >= 0) ? (float32)a.x : (float32)(1-a.x); float32 ay = (vertexScale.y >= 0) ? (float32)a.y : (float32)(1-a.y); bodyDef->anchorPoint = b2Vec2(ax, ay); CCArray *fixtureList = (CCArray*)(bodyData->objectForKey("fixtures")); FixtureDef **nextFixtureDef = &(bodyDef->fixtures); //iterate fixture list CCObject *arrayElem; CCARRAY_FOREACH(fixtureList, arrayElem) { b2FixtureDef basicData; CCDictionary* fixtureData = (CCDictionary*)arrayElem; basicData.filter.categoryBits = fixtureData->valueForKey("filter_categoryBits")->intValue(); basicData.filter.maskBits = fixtureData->valueForKey("filter_maskBits")->intValue(); basicData.filter.groupIndex = fixtureData->valueForKey("filter_groupIndex")->intValue(); basicData.friction = fixtureData->valueForKey("friction")->floatValue(); basicData.density = fixtureData->valueForKey("density")->floatValue(); basicData.restitution = fixtureData->valueForKey("restitution")->floatValue(); basicData.isSensor = fixtureData->valueForKey("isSensor")->intValue() != 0; int callbackData = fixtureData->valueForKey("userdataCbValue")->intValue(); const char* fixtureType = fixtureData->valueForKey("fixture_type")->getCString(); if (strcmp(fixtureType, "POLYGON")==0) { CCArray *polygonsArray = (CCArray *)(fixtureData->objectForKey("polygons")); CCObject *dicArrayElem; CCARRAY_FOREACH(polygonsArray, dicArrayElem) { FixtureDef *fix = new FixtureDef(); fix->fixture = basicData; // copy basic data fix->callbackData = callbackData; b2PolygonShape *polyshape = new b2PolygonShape(); int vindex = 0; CCArray *polygonArray = (CCArray*)dicArrayElem; assert(polygonArray->count() <= b2_maxPolygonVertices); CCObject *piter; CCARRAY_FOREACH(polygonArray, piter) { CCString *verStr = (CCString*)piter; CCPoint offset = CCPointFromString(verStr->getCString()); vertices[vindex] = b2Vec2((float32)(offset.x / ptmRatio) * vertexScale.x, (float32)(offset.y / ptmRatio) * vertexScale.y); vindex++; }
bool RestartLayer::init() { bool bRet = false; do { CC_BREAK_IF(!NavigatorLayer::init()); CCSize size = CCDirector::sharedDirector()->getWinSize(); // 1.头像 setHead(CCSprite::create()); m_pHead->initWithFile("Navigator_lose_image_1.png"); m_pHead->setPosition(ccp(150, 150)); m_pTV->addChild(m_pHead, 2); // 2.文字 CCSprite* pTitle = CCSprite::create(); pTitle->initWithFile("Navigator_lose_text.png"); pTitle->setPosition(ccp(350, 238)); m_pTV->addChild(pTitle, 2); // 3.重新开始的按钮 CCMenuItemImage *pRestartItem = CCMenuItemImage::create( "Btn_replay.png", "Btn_replay_pressed.png", "Btn_replay.png", this, menu_selector(RestartLayer::restartCallback)); CC_BREAK_IF(! pRestartItem); pRestartItem->setPosition(ccp(355, 80)); CCMenu* pMenu = CCMenu::create(pRestartItem, NULL); pMenu->setPosition(CCPointZero); CC_BREAK_IF(! pMenu); m_pTV->addChild(pMenu, 1); // 4.显示IQ数 CCString* str = CCString::createWithFormat("IQ: %d", m_nIQ); setIQLabel(CCLabelTTF::create(str->getCString(), "Arial", 30)); m_pIQLabel->setColor(ccBLACK); m_pIQLabel->setPosition(ccp(357, 160)); m_pIQLabel->getTexture()->setAliasTexParameters(); m_pTV->addChild(m_pIQLabel, 10); // init action CCAnimation* animation = CCAnimation::create(); animation->addSpriteFrameWithFileName("Navigator_lose_image_1.png"); animation->addSpriteFrameWithFileName("Navigator_lose_image_2.png"); animation->addSpriteFrameWithFileName("Navigator_lose_image_3.png"); animation->setDelayPerUnit(0.2f); CCAnimate* animate = CCAnimate::create(animation); setFlickerAction(CCRepeatForever::create(animate)); #if CC_TARGET_PLATFORM == CC_PLATFORM_IOS // 3.提示的按钮, 如果本关卡有提示点,才需要显示出来 setPromptItem(CCMenuItemImage::create( "Navigator_prompt.png", "Navigator_prompt_pressed.png", "Navigator_prompt.png", this, menu_selector(RestartLayer::promptCallback))); CC_BREAK_IF(! m_pPromptItem); m_pPromptItem->setPosition(ccp(235, 5)); pMenu->addChild(m_pPromptItem, 10); #endif bRet = true; }while(0); return bRet; }
MapItem* CData::getConfigOfMapLevel(int levelid) { if(m_config_map_level_dic->count()<1) { Json::Reader read; Json::Value root; Json::Value data; Json::Value list; string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("map.json"); CCString* str = CCString::createWithContentsOfFile(path.c_str()); int sz = 0; if(read.parse(str->getCString(), root)){ data = root["data"]; sz = data.size(); for (int i = 0; i < sz; i++) { MapItem *item = new MapItem(); // item->autorelease(); item->nickname = data[i]["name"].asString(); item->desc = data[i]["desc"].asString(); item->bid = data[i]["id"].asInt(); item->exp = data[i]["exp"].asInt(); item->coin = data[i]["coin"].asInt(); // item->itemId = root[i]["dropicon"].asInt(); list = data[i]["mconfig"]; CCDictionary* dic = CCDictionary::create(); int len =list.size(); for (int ei = 0; ei < len; ei++) { int iiiiid = list[ei].asInt(); configMonsterItem* hitem =CData::getCData()->getConfigOfMonster(iiiiid); if(hitem != NULL) { dic->setObject(hitem, hitem->nickname); } else{ char iii[100] = ""; sprintf(iii, "怪物id不存在 %d",iiiiid); CCLog(iii); } } char chars[500] = ""; int how = dic->count(); CCArray* arr = dic->allKeys(); switch (how) { case 1: sprintf(chars, "【%s】",((CCString*)(arr->objectAtIndex(0)))->getCString()); break; case 2: sprintf(chars, "【%s】\n【%s】",((CCString*)(arr->objectAtIndex(0)))->getCString(),((CCString*)(arr->objectAtIndex(1)))->getCString()); break; case 3: sprintf(chars, "【%s】 【%s】\n【%s】",((CCString*)(arr->objectAtIndex(0)))->getCString(),((CCString*)(arr->objectAtIndex(1)))->getCString(),((CCString*)(arr->objectAtIndex(2)))->getCString()); break; default: if(how >= 4) { sprintf(chars, "【%s】 【%s】\n【%s】 【%s】",((CCString*)(arr->objectAtIndex(0)))->getCString(), ((CCString*)(arr->objectAtIndex(1)))->getCString(), ((CCString*)(arr->objectAtIndex(2)))->getCString(),((CCString*)(arr->objectAtIndex(3)))->getCString()); } break; } item->enemydesc = chars; CCLog(item->enemydesc.c_str()); m_config_map_level_dic->setObject(item, item->bid); } } } return (MapItem*)m_config_map_level_dic->objectForKey(levelid); }
void HelloWorld::dumpUserInfo(CCGreeUser *user){ CCString *nickName = user->getNickname(); CCString *dispName = user->getDisplayName(); CCString *id = user->getId(); CCString *region = user->getRegion(); CCString *subRegion = user->getSubregion(); CCString *lang = user->getLanguage(); CCString *timeZone = user->getTimezone(); CCString *me = user->getAboutMe(); CCString *birthDay = user->getBirthday(); //CCString *url = pUser->getProfileUrl(); //CCLog("++++++ ProfileUrl %s", url->getCString()); CCString *gender = user->getGender(); CCString *age = user->getAge(); CCString *blood = user->getBloodType(); bool hasApp = user->getHasApp(); CCString *hash = user->getUserHash(); CCString *type = user->getUserType(); int grade = user->getUserGrade(); CCLog("++++++ NickName %s", nickName->getCString()); CCLog("++++++ DisplayName %s", dispName->getCString()); CCLog("++++++ Id %s", id->getCString()); CCLog("++++++ Region %s", region->getCString()); CCLog("++++++ Subregion %s", subRegion->getCString()); CCLog("++++++ Language %s", lang->getCString()); CCLog("++++++ Timezone %s", timeZone->getCString()); CCLog("++++++ me %s", me->getCString()); CCLog("++++++ BirthDay %s", birthDay->getCString()); CCLog("++++++ Gender %s", gender->getCString()); CCLog("++++++ Age %s", age->getCString()); CCLog("++++++ BloodType %s", blood->getCString()); CCLog("++++++ HasApp %d", hasApp); CCLog("++++++ UserHash %s", hash->getCString()); CCLog("++++++ UserType %s", type->getCString()); CCLog("++++++ grade %d", grade); }
void SGConsumableInfoLayer::initView() { ResourceManager::sharedInstance()->bindTexture("animationFile/qhtexiao.plist",RES_TYPE_LAYER_UI ,sg_comsumableInfoLayer); ResourceManager::sharedInstance()->bindTexture("sgequipslayer/sgequipslayer.plist",RES_TYPE_LAYER_UI ,sg_comsumableInfoLayer); ResourceManager::sharedInstance()->bindTexture("sggeneralinfolayer/sggeneralinfolayer1.plist",RES_TYPE_LAYER_UI ,sg_comsumableInfoLayer); ResourceManager::sharedInstance()->bindTexture("sgrewardlayer/sgrewardlayer2.plist",RES_TYPE_LAYER_UI ,sg_comsumableInfoLayer); ResourceManager::sharedInstance()->bindTexture("sgsoldierslayer/sgsoldierslayer.plist",RES_TYPE_LAYER_UI ,sg_comsumableInfoLayer, LIM_PNG_AS_PNG); ResourceManager::sharedInstance()->bindTexture("sgpropslayer/sgpropslayer.plist",RES_TYPE_LAYER_UI ,sg_comsumableInfoLayer); CCSize s = CCDirector::sharedDirector()->getWinSize(); float btmheight = SGMainManager::shareMain()->getBottomHeight(); //float frameheight = skewingY(155); float hgt = skewingY(244); if (s.height == 1136) { //frameheight = skewing(155); hgt = skewing(244); } //左火 CCSpriterX *fermEffect = CCSpriterX::create("animationFile/qhhyA.scml", true, true); fermEffect->setanimaID(0); fermEffect->setisloop(true); addChild(fermEffect, 10, 0); //右火 CCSpriterX *fermEffect1 = CCSpriterX::create("animationFile/qhhyB.scml", true, true); fermEffect1->setCCSpriterXFlipX(true); fermEffect1->setanimaID(0); fermEffect1->setisloop(true); addChild(fermEffect1, 10, 1); CCLOG("type%d",_card->getItemType()); // if (_card->getType()) { // statements // } SGMainManager::shareMain()->addPropPng(_card->getHeadSuffixNum(),sg_comsumableInfoLayer); CCString *str = CCString::createWithFormat("prop%d.png",_card->getHeadSuffixNum()); CCSprite *item = CCSprite::createWithSpriteFrameName(str->getCString()); this->addChild(item,2); item->setAnchorPoint(ccp(0.5, 0)); if (s.height == 960) { frameSize = CCRectMake(0, 0 , 768, 413); this->setItemID("pad装备底图.png",true); fermEffect->setScale(s.width/768); fermEffect1->setScale(s.width/768); fermEffect->setPosition(ccpAdd(SGLayout::getPoint(kUpCenter), ccp(-264, -287+26))); fermEffect1->setPosition(ccpAdd(SGLayout::getPoint(kUpCenter), ccp(264, -287+26))); item->setPosition(ccpAdd(SGLayout::getPoint(kUpCenter), ccp(0, -365))); } else if (s.height == 1136) { frameSize = CCRectMake(0, 520 -(s.height - hgt*1.13 - title_bg->getContentSize().height), 768, (s.height - hgt*1.13 - title_bg->getContentSize().height)); this->setItemID("carditembg.png",true); fermEffect->setScaleX(s.width/768); fermEffect1->setScaleX(s.width/768); fermEffect->setPosition(ccpAdd(SGLayout::getPoint(kUpCenter), ccp(-264, -361+26))); fermEffect1->setPosition(ccpAdd(SGLayout::getPoint(kUpCenter), ccp(264, -361+26))); item->setPosition(ccpAdd(SGLayout::getPoint(kUpCenter), ccp(0, -450))); }else { CCSprite *a = CCSprite::createWithSpriteFrameName("pad装备底图.png"); this->addChild(a,-100); a->setPosition(ccpAdd(SGLayout::getPoint(kUpCenter), ccp(0, - title_bg->getContentSize().height - a->getContentSize().height*.45))); fermEffect->setPosition(ccpAdd(a->getPosition(), ccp(-a->getContentSize().width*.41, a->getContentSize().height*.02 -a->getContentSize().height*.09))); fermEffect1->setPosition(ccpAdd(a->getPosition(), ccp(a->getContentSize().width*.41, a->getContentSize().height*.02-a->getContentSize().height*.09))); item->setPosition(ccpAdd(a->getPosition(), ccp(0, -a->getContentSize().height*.362))); } fermEffect->play(); fermEffect1->play(); menu->setZOrder(7); this->setstar(_card->getCurrStar()); this->setTitle(_card->getOfficerName()->getCString()); SGButton *backBtn = SGButton::createFromLocal("store_exchangebtnbg.png", str_back, this, menu_selector(SGConsumableInfoLayer::backHandler),CCPointZero,FONT_PANGWA,ccWHITE,32); backBtn->setScale(1.05); this->addBtn(backBtn); backBtn->setPosition(ccpAdd(SGLayout::getPoint(kUpLeft), ccp( backBtn->getContentSize().width*.55, - backBtn->getContentSize().height*.55))); if(enterType == 101) { ResourceManager::sharedInstance()->bindTexture("sanguobigpic/barrack_bg.plist", RES_TYPE_LAYER_UI, sg_comsumableInfoLayer); CCSprite *bg1 = CCSprite::create("storyBg.png"); //CCRect r = CCRectMake(0, 1136/2 - (hgt*1.13)/2, s.width, hgt*1.13); //bg1->setTextureRect(r); bg1->setScaleY(s.height/2 / bg1->getContentSize().height); bg1->setScaleX(s.width / bg1->getContentSize().width); bg1->setAnchorPoint(ccp(0.5, 0)); bg1->setPosition(SGLayout::getPoint(kBottomCenter)); this->addChild(bg1,5); } else { CCSprite *bg1 = CCSprite::createWithSpriteFrameName("info_redbg.png"); bg1->setAnchorPoint(ccp(0.5, 0)); bg1->setScaleX(s.width/bg1->getContentSize().width); bg1->setScaleY((hgt*1.13-btmheight*.68)/bg1->getContentSize().height); bg1->setPosition(ccpAdd(SGLayout::getPoint(kBottomCenter), ccp(0, btmheight*.68 ))); this->addChild(bg1,5); } CCSprite* jinbian = CCSprite::createWithSpriteFrameName("jinbian.png"); jinbian->setPosition(ccp(s.width/2, hgt*1.13)); jinbian->setScaleX(s.width/jinbian->getContentSize().width); this->addChild(jinbian,6); CCScale9Sprite *frame2 = CCScale9Sprite::createWithSpriteFrameName("barrack_kuang.png"); frame2->setPreferredSize(CCSizeMake(568+20, 320)); this->addChild(frame2,7); frame2->setPosition(ccpAdd(jinbian->getPosition(), ccp(0, -frame2->getContentSize().height/2 - 30))); CCSprite *frame2bg = CCSprite::createWithSpriteFrameName("barrack_kuangbg.png"); this->addChild(frame2bg,6); frame2bg->setScaleX(590/frame2bg->getContentSize().width); frame2bg->setScaleY(320/frame2bg->getContentSize().height); frame2bg->setPosition(frame2->getPosition()); CCSprite *guang2l = CCSprite::createWithSpriteFrameName("barrack_kuang_guangl.png"); this->addChild(guang2l,6); guang2l->setAnchorPoint(ccp(0, 1)); CCSprite *guang2r = CCSprite::createWithSpriteFrameName("barrack_kuang_guangl.png"); this->addChild(guang2r,6); guang2r->setFlipX(true); guang2r->setAnchorPoint(ccp(1, 1)); CCSprite *guang2m = CCSprite::createWithSpriteFrameName("barrack_kuang_guangm.png"); this->addChild(guang2m,6); guang2m->setScaleX(468/guang2m->getContentSize().width); guang2m->setAnchorPoint(ccp(0.5, 1)); guang2m->setPosition(ccpAdd(frame2->getPosition(), ccp(0, frame2->getContentSize().height*.5))); guang2r->setPosition(ccpAdd(guang2m->getPosition(), ccp(284+10, 0))); guang2l->setPosition(ccpAdd(guang2m->getPosition(), ccp(-284-10, 0))); CCScale9Sprite *fontbg = CCScale9Sprite::createWithSpriteFrameName("box_fontbg.png"); fontbg->setPreferredSize(CCSizeMake(538, 205)); this->addChild(fontbg,6); fontbg->setPosition(ccpAdd(frame2->getPosition(), ccp(0, 26))); SGConsumableDataModel *temp = SGStaticDataManager::shareStatic()->getConsumableById(_card->getItemId()); SGCCLabelTTF* a = SGCCLabelTTF::create(temp->getConsumeDesc()->getCString(), FONT_BOXINFO, 28, CCSizeMake(504,400)); a->setAnchorPoint(ccp(0.5f, 1)); this->addChild(a,6); a->setPosition(ccpAdd(fontbg->getPosition(), ccp(0, fontbg->getContentSize().height*.33))); //setCardType,“强化合成“ SGConsumableDataModel *consumeData = SGStaticDataManager::shareStatic()->getConsumableById(_card->getItemId()); this->setCardType(consumeData->getConsumeType()); }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); // turn on display FPS //pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); //check for first launch if( getSystem()->isFirstLaunch() ){ //clear update folder CCLOG("-- FIRST LAUNCH --"); string docpath; getSystem()->getDocumentPath(docpath); string udpath = docpath + "update/"; getSystem()->removeDirectory(udpath); string dypath = docpath + "dynamic.json"; getSystem()->removeDirectory(dypath); } CCDictionary *pSetup = CCDictionary::createWithContentsOfFile("Setup.plist"); string display; {//set display CCSize winSize = pDirector->getWinSize(); float aspectRatio = winSize.height/winSize.width; CCArray *pResolutions = (CCArray*)pSetup->objectForKey("Resolutions"); if( pResolutions != NULL ) { float fitScore = 10; float fitWidth = 0; float fitHeight = 0; bool isFitable = false; CCObject *pObj = NULL; CCARRAY_FOREACH(pResolutions, pObj) { CCDictionary *pRes = (CCDictionary*)pObj; CCString *pPath = (CCString*)pRes->objectForKey("path"); CCString *pWidth = (CCString*)pRes->objectForKey("width"); CCString *pHeight = (CCString*)pRes->objectForKey("height"); float width, height, score; sscanf(pWidth->getCString(), "%f", &width); sscanf(pHeight->getCString(), "%f", &height); if (winSize.height == height) { isFitable = true; } if( winSize.width >= width && winSize.height >= height ) { score = 0; float aspect = height/width; float dist = fabsf(aspect - aspectRatio); if( dist < fitScore ) { fitScore = dist; fitWidth = width; fitHeight = height; display = pPath->getCString(); } } else { score = 8; } } if(fitWidth == 0 || fitHeight == 0) { fitWidth = 640; fitHeight = 960; display = "960/"; } //set best resolution if (isFitable){ pDirector->getOpenGLView()->setDesignResolutionSize(fitWidth, fitHeight, kResolutionShowAll); } getSystem()->setViewSizeHeight((int)fitHeight); getSystem()->setViewSizeWidth((int)fitWidth); CCLog("Resolution Adapter: %dx%d (%s) = %f", (int)fitWidth, (int)fitHeight, display.c_str(), fitScore); }
void SGAdvancedEffectLayer::initView() { // ccColor3B color[4] = {ccc3(0 , 239 , 22) , ccc3(75, 147, 255) ,ccc3(215,56,255) , ccc3(249, 158, 0)}; // // ccColor3B titleColor; ResourceManager::sharedInstance()->bindTexture("animationFile/Lightspot.plist",RES_TYPE_LAYER_UI ,sg_advancedEffectLayer); ResourceManager::sharedInstance()->bindTexture("animationFile/VisitArray.plist",RES_TYPE_LAYER_UI ,sg_advancedEffectLayer); int adNum = 0; int quality=0; //类型是全局通用的那个物品类型 char beforeItemPicStr[32] = "\0"; char afterItemPicStr[32] = "\0"; char itemNameStr[32] = "\0"; char itemAdNum[32] = "\0";// 小转生次次数 //6:将领卡牌 7:装备卡牌 8:士兵卡牌 9:道具卡牌 1:铜钱 0:金子 2天梯积分 3:军功 5:炼丹秘方 4:小喇叭 10:碎片 11军魂 12体力 13军粮 14号(废弃) 15消耗品 16 勋章 17 材料 //各种类型参数 switch (itemType) { case BIT_EQUIP://装备卡牌 { SGEquipmentDataModel *beforeEquipModel = SGStaticDataManager::shareStatic()->getEquipById(beforeAdvanceItemId); SGEquipmentDataModel *afterEquipModel = SGStaticDataManager::shareStatic()->getEquipById(afterAdvanceItemId); int beforeId = beforeEquipModel->getIconId(); int afterId = afterEquipModel->getIconId(); SGMainManager::shareMain()->addEquipPng(beforeId, sg_advancedEffectLayer); SGMainManager::shareMain()->addEquipPng(afterId, sg_advancedEffectLayer); sprintf(beforeItemPicStr, "equip%d.png", beforeId); sprintf(afterItemPicStr, "equip%d.png", afterId); sprintf(itemNameStr, "%s", afterEquipModel->getEquipName()->getCString()); adNum = afterEquipModel->getAdvNum(); if (adNum > 0) { sprintf(itemAdNum, "+%d", adNum); } //装备边框颜色 quality = afterEquipModel->getEquipCurrStarLevel(); // if(quality < 3 || quality > 6) // titleColor = ccGREEN; // else // titleColor = color[quality - 3]; } break; case BIT_OFFICER://武将卡牌 { SGOfficerDataModel *beforeEquipModel = SGStaticDataManager::shareStatic()->getOfficerById(beforeAdvanceItemId); SGOfficerDataModel *afterEquipModel = SGStaticDataManager::shareStatic()->getOfficerById(afterAdvanceItemId); int beforeId = beforeEquipModel->getIconId(); int afterId = afterEquipModel->getIconId(); SGMainManager::shareMain()->addOfficerPng(beforeId, sg_advancedEffectLayer); SGMainManager::shareMain()->addOfficerPng(afterId, sg_advancedEffectLayer); sprintf(beforeItemPicStr, "officer_%d.png", beforeId); sprintf(afterItemPicStr, "officer_%d.png", afterId); sprintf(itemNameStr, "%s", afterEquipModel->getOfficerName()->getCString()); adNum = afterEquipModel->getAdvNum(); if (adNum > 0) { sprintf(itemAdNum, "+%d", adNum); } //装备边框颜色 quality = afterEquipModel->getOfficerCurrStarLevel(); // if(quality < 3 || quality > 6) // titleColor = ccGREEN; // else // titleColor = color[quality - 3]; break; } default: break; } //构造sprite beforeAdvancedItemPic = CCSprite::createWithSpriteFrameName(beforeItemPicStr); afterAdvancedItemPic = CCSprite::createWithSpriteFrameName(afterItemPicStr); itemName = SGCCLabelTTF::create(itemNameStr, FONT_PANGWA, 35, SGTools::getColorByQuality(quality)); if (adNum) { adNumLabel = SGCCLabelTTF::create(itemAdNum, FONT_PANGWA, 34, ccGREEN); } //黑背景 CCLayerColor *blackBg = CCLayerColor::create(ccc4(0, 0, 0, 255), CCDirector::sharedDirector()->getWinSize().width, CCDirector::sharedDirector()->getWinSize().height); this->addChild(blackBg, 0); blackBg->setPosition(ccp(0, 0)); blackBg->addChild(beforeAdvancedItemPic, 1); blackBg->addChild(itemName, 1); beforeAdvancedItemPic->setPosition(ccpAdd(blackBg->getPosition(), ccp(blackBg->getContentSize().width / 2, blackBg->getContentSize().height / 2))); itemName->setPosition(ccpAdd(beforeAdvancedItemPic->getPosition(), ccp(0, beforeAdvancedItemPic->getContentSize().height / 2 + itemName->getContentSize().height + 20))); if (adNumLabel) { blackBg->addChild(adNumLabel, 1); adNumLabel->setPosition(ccpAdd(itemName->getPosition(), ccp(itemName->getContentSize().width / 2 + 10 + adNumLabel->getContentSize().width, 0))); } CCSize winSize = CCDirector::sharedDirector()->getWinSize(); //添加动画 法阵旋转 CCSpriterX *visitArray = CCSpriterX::create("animationFile/Array.scml",true,true); visitArray->setisloop(true); visitArray->play(); visitArray->setanimaID(0); blackBg->addChild(visitArray,1); visitArray->setPosition(ccp(winSize.width/2, winSize.height*(0.8-0.28) - 50)); //法阵上升粒子 CCSpriterX *lightSpot = CCSpriterX::create("animationFile/Lightspot.scml",true,true); lightSpot->setisloop(true); lightSpot->play(); lightSpot->setanimaID(0); blackBg->addChild(lightSpot,50); lightSpot->setPosition(ccp(winSize.width/2, winSize.height*(0.8-0.2))); //构造动画 CCCallFuncN *setPicVisiable = CCCallFuncN::create(this, callfuncN_selector(SGAdvancedEffectLayer::setPictureVisiable)); CCCallFuncN *setTipsVisiable = CCCallFuncN::create(this, callfuncN_selector(SGAdvancedEffectLayer::setSuccessTipsVisiable)); CCCallFuncN *setComplete = CCCallFuncN::create(this, callfuncN_selector(SGAdvancedEffectLayer::setisPlayCompleted)); afterAdvancedItemPic->setScale(5); blackBg->addChild(afterAdvancedItemPic, 2); afterAdvancedItemPic->setPosition(beforeAdvancedItemPic->getPosition()); CCString * str = NULL; int fSize = 36; if(m_officerFrom == 1) str = CCString::create(str_adv_eff_1); else if (2 == m_officerFrom) str = CCString::create(str_adv_eff_2); else if(-1 == m_officerFrom) str = CCString::create(str_adv_eff_1); else if (3 == m_officerFrom) { str = CCString::createWithFormat(str_adv_eff_3, _extArg); fSize = 26; } else { //默认只显示 『转生成功』 str = CCString::create(str_adv_eff_1); } successTips = SGCCLabelTTF::create(str->getCString(), FONT_PANGWA, fSize); blackBg->addChild(successTips, 3); successTips->setPosition(ccpAdd(afterAdvancedItemPic->getPosition(), ccp(0, -afterAdvancedItemPic->getContentSize().height / 2 - successTips->getContentSize().height - 100))); successTips->setVisible(false); CCSequence *seq = CCSequence::create(CCDelayTime::create(0.1),setPicVisiable, CCScaleTo::create(SHOWCARDGAPTIME*2,0.89), CCScaleTo::create(SHOWCARDGAPTIME,1.13), CCScaleTo::create(SHOWCARDGAPTIME,1.06), CCScaleTo::create(SHOWCARDGAPTIME,1), CCDelayTime::create(0.15), setTipsVisiable, CCDelayTime::create(0.15), setComplete, NULL); afterAdvancedItemPic->runAction(seq); CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, -255, true); }
void MapScene::update(float dt) { CCSize size = CCDirector::sharedDirector()->getWinSize(); CCPoint maplayer1p = maplayer1->getPosition(); CCPoint maplayer2p = maplayer2->getPosition(); maplayer1->setPosition(ccp(maplayer1p.x - 5,maplayer1p.y)); maplayer2->setPosition(ccp(maplayer2p.x - 5,maplayer2p.y)); if(maplayer2p.x < 0){ float temp = maplayer2p.x + 242; maplayer1->setPosition(ccp(temp,maplayer1p.y)); } if(maplayer1p.x < 0){ float temp = maplayer1p.x + 242; maplayer2->setPosition(ccp(temp,maplayer2p.y)); } for(int j = enemyList->count() - 1; j >= 0; j--) { GameEnemy *enemy = (GameEnemy *)(enemyList->objectAtIndex(j)); if(enemy->getState() != -1) { enemy->tick(); for(int i = playerBulletList->count() - 1; i >= 0; i--) { GameBullet * mybullet = (GameBullet *)(playerBulletList->objectAtIndex(i)); if(enemy->collisionwithbullet(mybullet)) { enemyList->removeObjectAtIndex(j); this->removeChild(enemy->getsprite(), true); delete enemy; playerBulletList->removeObjectAtIndex(i); this->removeChild(mybullet->getsprite(),true); delete mybullet; playerscore++; this->updateLife(1); CCString *scoreLa = CCString::createWithFormat("%i",playerscore); scoreLabel->setString(scoreLa->getCString()); break; } } } } for(int i = 0; i < playerBulletList->count(); i++) { GameBullet* mybullet = (GameBullet *)(playerBulletList->objectAtIndex(i)); mybullet->tick(); if((mybullet->getsprite())->getPosition().x > size.width){ playerBulletList->removeObjectAtIndex(i); this->removeChild(mybullet->getsprite(),true); delete mybullet; } } for(int i = 0; i < enemyList->count(); i++) { GameEnemy* enemy = (GameEnemy *)(enemyList->objectAtIndex(i)); if((enemy->getsprite())->getPosition().x < 0){ this->updateLife(-10); enemyList->removeObjectAtIndex(i); this->removeChild(enemy->getsprite(),true); delete enemy; } } //let player move to targetPoint if(joyStick->getVelocity() > 0) { CCPoint orginP = (player->getsprite())->getPosition(); CCPoint direP = ccpMult(joyStick->getDirection(), player->getSpeed()); CCPoint lastP = ccp(orginP.x + direP.x, orginP.y + direP.y); float minx = (player->getsprite())->getContentSize().width/2; float maxx = size.width - minx; float miny = bottomMenu->getContentSize().height + (player->getsprite())->getContentSize().height/2; float maxy = size.height - (player->getsprite())->getContentSize().height/2; if(lastP.x <= minx) lastP.x = minx; else if(lastP.x >= maxx) lastP.x = maxx; if(lastP.y <= miny) lastP.y = miny; else if(lastP.y >= maxy) lastP.y = maxy; (player->getsprite())->setPosition(lastP); } }
bool ResultScene::initWithParam(int level, int minScore, int resultScore) { // 初期化色を変更 if (!CCLayerColor::initWithColor(ccc4(0xF8,0xEC,0xDE,0xFF))) //RGBA { return false; } //初期化に関するものを書く m_level = level; CCSize winSize = CCDirector::sharedDirector()->getWinSize(); //RESULTの文字 CCLabelTTF* resultLabel; resultLabel = CCLabelTTF::create("RESULT", "Arial", 100.0); resultLabel->setColor(ccc3(0, 0, 0)); resultLabel->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.9)); this->addChild(resultLabel); //今回のスコア CCString* resultScoreStr = CCString::createWithFormat("TOUCH : %d",resultScore); CCLabelTTF* resultScoreLabel; resultScoreLabel = CCLabelTTF::create(resultScoreStr->getCString(), "Arial", 60.0); resultScoreLabel->setColor(ccc3(0, 0, 0)); resultScoreLabel->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.6)); this->addChild(resultScoreLabel); //今回のLv CCString* levelStr = CCString::createWithFormat("Lv : %d",level); CCLabelTTF* levelLabel; levelLabel = CCLabelTTF::create(levelStr->getCString(), "Arial", 60.0); levelLabel->setColor(ccc3(0, 0, 0)); levelLabel->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.7)); this->addChild(levelLabel); int rank; if(minScore >= resultScore){ rank = 3; //Game Center Cocos2dExt::NativeCodeLauncher::postAchievement(level, 100); }else if( minScore <= resultScore + 8){ rank = 2; }else{ rank = 1; } for (int i=0; i < rank; i++) { CCSprite* pStar = CCSprite::create("star.png"); pStar->setScale(0.2); float posX; if(i == 0){ posX = 0.3; }else if(i == 1){ posX = 0.5; }else{ posX = 0.7; } pStar->setPosition(ccp(winSize.width * posX, winSize.height * 0.8)); this->addChild(pStar); } //リトライボタン CCMenuItemImage* pRetryItem; pRetryItem = CCMenuItemImage::create("reload.png", "reload.png",this,menu_selector(ResultScene::replayGame)); pRetryItem->setScale(0.3); pRetryItem->setPosition(ccp(winSize.width * 0.3, winSize.height * 0.3)); //次のレベルへ CCMenuItemImage* pNextLevelItem; if (m_level == max_level){ pNextLevelItem = CCMenuItemImage::create("next.png", "next.png",this,menu_selector(ResultScene::showTitleMenu)); }else{ pNextLevelItem = CCMenuItemImage::create("next.png", "next.png",this,menu_selector(ResultScene::nextLevelGame)); } pNextLevelItem->setScale(0.3); pNextLevelItem->setPosition(ccp(winSize.width * 0.7, winSize.height * 0.3)); CCMenu* pMenu = CCMenu::create(pRetryItem,pNextLevelItem,NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu); return true; }
void GameLayer_GoldMarket::buyBtnCallback(cocos2d::CCObject *pSender) { UIButton* button = (UIButton*)pSender; GameLayer_Alert *alertUl = GameLayer_Alert::creatWithOnlySure(Type_Noraml); alertUl->setSureCallbackFunc(this, callfuncO_selector(GameLayer_GoldMarket::sureBuyCallback)); alertUl->setSureBtnTag(button->getTag()); SMoneySysChgTempData* pData; switch (button->getTag()) { case Buy_0: { pData = CMoneyMan::sharedInstance().getChgTempData(DiamondToGold_1); if (pData) { CCString str; str.initWithFormat(GET_STRING_CSV(101000001), pData->ExchangeFromValue,pData->ExchangeToValue); alertUl->setText(str.getCString()); } } break; case Buy_1: //alertUl->setText("确定要用10宝石兑换4500金币吗?"); { pData = CMoneyMan::sharedInstance().getChgTempData(DiamondToGold_2); if (pData) { CCString str; str.initWithFormat(GET_STRING_CSV(101000002), pData->ExchangeFromValue,pData->ExchangeToValue); alertUl->setText(str.getCString()); } } break; case Buy_2: //alertUl->setText("确定要用50宝石兑换1200金币吗?"); { pData = CMoneyMan::sharedInstance().getChgTempData(DiamondToGold_3); if (pData) { CCString str; str.initWithFormat(GET_STRING_CSV(101000003), pData->ExchangeFromValue,pData->ExchangeToValue); alertUl->setText(str.getCString()); } } break; case Buy_3: //alertUl->setText("确定要用100宝石兑换10000金币吗?"); { pData = CMoneyMan::sharedInstance().getChgTempData(DiamondToGold_4); if (pData) { CCString str; str.initWithFormat(GET_STRING_CSV(101000004), pData->ExchangeFromValue,pData->ExchangeToValue); alertUl->setText(str.getCString()); } } break; case Buy_4: //alertUl->setText("确定要用500宝石兑换60000金币吗?"); { pData = CMoneyMan::sharedInstance().getChgTempData(DiamondToGold_5); if (pData) { CCString str; str.initWithFormat(GET_STRING_CSV(101000005), pData->ExchangeFromValue,pData->ExchangeToValue); alertUl->setText(str.getCString()); } } break; default: break; } if (CPlayerInfoMan::sharedInstance().getPlayerInfo().nGem-pData->ExchangeFromValue < 0) { // GameLayer_Alert *alertUl = GameLayer_Alert::creatWithOnlySure(Type_OnlySure); //alertUl->setText(GET_STRING_CSV(1010000022)); //this->addChild(alertUl); return; } this->addChild(alertUl); }
void HPDPS::refreshHP() { CCString* string = CCString::createWithFormat("%.0f",(100 - progressTimer->getPercentage()) * Interface::sharedInterface()->hpConversion); hp->setString(string->getCString()); }
void Planet::initWithForceSide( int force ) { Planet::init(); m_nForceSide = force; // 星球 if(force == kForceSideCat) { initWithFile("Planet_cat.png"); } else if(force == kForceSideDog) { initWithFile("Planet_dog.png"); } else if(force == kForceSideThird) { initWithFile("Planet_third.png"); } else if(force == kForceSideMiddle) { initWithFile("Planet_middle.png"); } else { return; } // 中间的脸 CCSize planetSize = boundingBox().size; if(!m_pFace) { Face* pFace = Face::createWithForceSide(force); setFace(pFace); m_pFace->setPosition(ccp(planetSize.width / 2 + 3, planetSize.height / 2 - 3)); this->addChild(m_pFace); } else m_pFace->initWithForceSide(force); // 右上角的数字 CCString* pStr = CCString::createWithFormat("%d", getFightUnitCount()); if(!m_pFightUnitLabel) { setFightUnitLabel(CCLabelTTF::create(" ", FONT_00_STARMAP_TRUETYPE, 19)); int x = planetSize.width - 16; int y = planetSize.height - 16; // 对于ios再微调一下 #if CC_TARGET_PLATFORM == CC_PLATFORM_IOS x -= 1; y -= 2; #endif m_pFightUnitLabel->setPosition(ccp(x, y)); this->addChild(m_pFightUnitLabel); } if(m_nForceSide != kForceSideMiddle) { ccColor3B ccMyOrange={255, 104, 0}; m_pFightUnitLabel->setColor(ccMyOrange); } else { ccColor3B ccMyGray={72, 72, 72}; m_pFightUnitLabel->setColor(ccMyGray); } m_pFightUnitLabel->setString(pStr->getCString()); // 每次init之后stopped都会被置为false // 主要是因为当把一个middel星设为stop后,被另一方占领需要自动恢复成正常增加 m_bIncreaseStopped =false; // b2Body创建 // setLevel(0); slowDownRestore(0); setScale(1); }