void XQDate::SaveDate(void *pDataPkg, CCObject* target, SEL_MyEvent callfun) { //读取数据,以key,value形势组成MyXQDate,并存入myCacheList中,key为msg_type + msg_code,例如,请求为1,2,则key为字符串“12”; NetCallBack::setCallBack(target, callfun); CResponsePacket* pPkt = (CResponsePacket*)pDataPkg; unsigned int unMsgType = pPkt->getMsgType(); unsigned int unMsgCode = pPkt->getMsgCode(); CSJson::Value root ; if (!CJsonHelper::getJsonFromString(pPkt->getContent().c_str(),root)) { } CCString str; str.initWithFormat("%d%d",unMsgType, unMsgCode); if (unMsgType == 6 && unMsgCode == 5) { str.initWithFormat("%d%d%d",unMsgType, unMsgCode, GameType); } if (HaveDate(str.getCString())) { for (int i = 0; i < myCacheList.size(); i++) { if (myCacheList[i].keyId == str.getCString()) { myCacheList[i].root = root; } } } else { MyXQDate data; data.keyId = str.getCString(); data.root = root; myCacheList.push_back(data); } NetCallBack::doCallBack(); }
static void array_Value(CCArray * aArray, const cocos2d::ValueVector & value) { cocos2d::ValueVector::const_iterator beg = value.begin(); cocos2d::ValueVector::const_iterator end = value.end(); for (; beg != end; ++beg) { const Value & v = *beg; if (v.getType() == Value::Type::MAP) { CCDictionary * dict = new CCDictionary(); dict->init(); dictionary_Value(dict, v.asValueMap()); aArray->addObject(dict); dict->release(); } else if (v.getType() == Value::Type::VECTOR) { CCArray * arr = new CCArray(); arr->init(); array_Value(arr, v.asValueVector()); aArray->addObject(arr); arr->release(); } else { CCString * str = new CCString(); if (v.getType() == Value::Type::DOUBLE) str->initWithFormat("%f", v.asDouble()); else str->initWithFormat("%s", v.asString().c_str()); aArray->addObject(str); str->release(); } } }
CCSprite* FightInfoLayer::getSpriteByScore(long score, CCPoint p,int kind) { long temp = score; //位数,用于设置横坐标偏移量. int digit = 0; CCSprite* scroeSprite = CCSprite::create(); scroeSprite ->setPosition(p); while (temp>0 || (digit==0 && temp==0)) { int remainder = temp % 10; temp = temp/10; CCSprite *m_Sprite; CCRect rc; CCString str; if(kind==2) str.initWithFormat("s_%d.png", remainder); else str.initWithFormat("f_%d.png", remainder); m_Sprite = CCSprite::createWithSpriteFrameName(str.getCString()); if(kind==2) m_Sprite->setPosition(ccp((digit+(digit/3))*(-21), 0)); else m_Sprite->setPosition(ccp((digit+(digit/3))*(-15), -5)); scroeSprite->addChild(m_Sprite); scroeSprite -> setPosition(ccp(scroeSprite->getPositionX() - 6, scroeSprite->getPositionY())); if(kind==2) m_Sprite->setScale(1.5); if (digit%3==0 && digit>0) { CCSprite *comma; if(kind==2) { comma= CCSprite::createWithSpriteFrameName("s_point.png"); comma->setPosition(ccp(m_Sprite->getPositionX()+25, -5)); scroeSprite->addChild(comma); comma->setScale(1.5); scroeSprite -> setPosition(ccp(scroeSprite->getPositionX() - 10, scroeSprite->getPositionY())); } else { comma= CCSprite::createWithSpriteFrameName("f_point.png"); comma->setPosition(ccp(m_Sprite->getPositionX()+19, -10)); scroeSprite->addChild(comma); scroeSprite -> setPosition(ccp(scroeSprite->getPositionX() - 6, scroeSprite->getPositionY())); } } digit++; } digit--; CCArray* array = scroeSprite->getChildren(); for (int i=0; i<array->count(); i++) { CCPoint point = ((CCSprite*)array->objectAtIndex(i))->getPosition(); point.x += (digit+(digit/3))*15.0; ((CCSprite*)array->objectAtIndex(i))->setPosition(point); } return scroeSprite; }
void Scene_GameItem::itemBtnCallBack(cocos2d::CCObject *object) { UIButton* btn = (UIButton*)object; UIImageView* img; //通过游戏的道具信息获取道具价钱. sItemData* itemData = CGameInfoMan::sharedInstance().getItemDate(GameShare_Global::shareGlobal()->gameType, btn->getTag()); UILabel* itemInfo = dynamic_cast<UILabel*>(ul->getWidgetByName("Label_591")); switch (btn->getTag()) { case Btn_1: img = dynamic_cast<UIImageView*>(ul->getWidgetByName("IsSelectImg_1")); break; case Btn_2: img = dynamic_cast<UIImageView*>(ul->getWidgetByName("IsSelectImg_2")); break; case Btn_3: img = dynamic_cast<UIImageView*>(ul->getWidgetByName("IsSelectImg_3")); break; case Btn_4: img = dynamic_cast<UIImageView*>(ul->getWidgetByName("IsSelectImg_4")); break; default: break; } if (img->isVisible()) { img->setVisible(false); if (itemData) { CCString infoStr; infoStr.initWithFormat("%s:%s",itemData->ItemName.c_str(),itemData->ItemDetail.c_str()); itemInfo->setText(infoStr.getCString()); needGold -= itemData->CurrencyValue; } }else{ img->setVisible(true); if (itemData) { CCString infoStr; infoStr.initWithFormat("%s:%s",itemData->ItemName.c_str(),itemData->ItemDetail.c_str()); itemInfo->setText(infoStr.getCString()); needGold += itemData->CurrencyValue; if (CPlayerInfoMan::sharedInstance().getPlayerInfo().nMoney < needGold) { GameLayer_Alert *alertUl = GameLayer_Alert::creatWithOnlySure(Type_OnlySure); needGold -= itemData->CurrencyValue; alertUl->setText(GET_STRING_CSV(1010000021)); this->addChild(alertUl,1); img->setVisible(false); } } } this->setItemByTag(btn->getTag()); }
/** * This initializing method should be used if game object has animation frames. * It loads a new sprite sheet for the game object, if it isn't already loaded. * Next it creates animation frames using the sprite sheet. * After that, it creates a new sprite and adds it as a child of the sprite sheet. * * @param textureFileName Name of a file containing game object textures. * @param frameNamePrefix Frames are described in plist file in "prefixNumber" format, e.g. "balloon2.png". * This param describes the prefix, e.g. "balloon". * @param frameCount The number of animation frames. * @param delay Time in seconds between animation frames. * @param layer Layer that will hold the sprite sheet. * @param spriteSheetTag Tag describing the sprite sheet. */ void AnimatedObject::init( CCString textureFileName, CCString frameNamePrefix, int frameCount, float delay, CCLayer* layer, AnimTag spriteSheetTag) { //Get the sprite sheet. __pSpriteSheet = (CCSpriteBatchNode*)layer->getChildByTag(spriteSheetTag); if(__pSpriteSheet == NULL) { //Create a new sprite sheet if it dosen't exit. const char* textureFileNameC = textureFileName.getCString(); __pSpriteSheet = CCSpriteBatchNode::create(textureFileNameC); __pSpriteSheet->setTag(spriteSheetTag); layer->addChild(__pSpriteSheet, 1); } //Get animation frames. __pAnimationFrames = new CCArray(); for(int i = 1; i <= frameCount; ++i) { CCString f = "%s%d.png"; CCString frameName = ""; frameName.initWithFormat(f.getCString(), frameNamePrefix.getCString(), i); const char* frameNameC = (const char*)frameName.getCString(); CCSpriteFrame* spriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frameNameC); __pAnimationFrames->addObject(spriteFrame); // __pAnimationFrames->addObject(frameName); } //Create animation CCAnimation* animation = CCAnimation::createWithSpriteFrames(__pAnimationFrames, delay); __pAnimationAction = CCRepeatForever::create(CCAnimate::create(animation)); CCSize size = CCDirector::sharedDirector()->getWinSize(); CCString f = "%s1.png"; CCString frameName = ""; frameName.initWithFormat(f.getCString(), frameNamePrefix.getCString()); //Create game object sprite and add it to the sprite sheet. const char* frameNameC = frameName.getCString(); __pSprite = CCSprite::createWithSpriteFrameName(frameNameC); __pSprite->setPosition(ccp(size.width / 2, size.height / 2)); __pSprite->runAction(__pAnimationAction); __pSpriteSheet->addChild(__pSprite); }
void GameLayer_GoldMarket::setValue() { UILabel* diamondNum_0 = dynamic_cast<UILabel*>(goldMarket->getWidgetByName("DiamondNum_0")); UILabelAtlas* goldNum_0 = dynamic_cast<UILabelAtlas*>(goldMarket->getWidgetByName("GoldNum_0")); SMoneySysChgTempData* pData = CMoneyMan::sharedInstance().getChgTempData(DiamondToGold_1); if (pData) { CCString str; str.initWithFormat("%d", pData->ExchangeFromValue); diamondNum_0->setText(str.getCString()); str.initWithFormat("%d",pData->ExchangeToValue); goldNum_0->setStringValue(str.getCString()); } UILabel* diamondNum_1 = dynamic_cast<UILabel*>(goldMarket->getWidgetByName("DiamondNum_1")); UILabelAtlas* goldNum_1 = dynamic_cast<UILabelAtlas*>(goldMarket->getWidgetByName("GoldNum_1")); pData = CMoneyMan::sharedInstance().getChgTempData(DiamondToGold_2); if (pData) { CCString str; str.initWithFormat("%d", pData->ExchangeFromValue); diamondNum_1->setText(str.getCString()); str.initWithFormat("%d",pData->ExchangeToValue); goldNum_1->setStringValue(str.getCString()); } UILabel* diamondNum_2 = dynamic_cast<UILabel*>(goldMarket->getWidgetByName("DiamondNum_2")); UILabelAtlas* goldNum_2 = dynamic_cast<UILabelAtlas*>(goldMarket->getWidgetByName("GoldNum_2")); pData = CMoneyMan::sharedInstance().getChgTempData(DiamondToGold_3); if (pData) { CCString str; str.initWithFormat("%d", pData->ExchangeFromValue); diamondNum_2->setText(str.getCString()); str.initWithFormat("%d",pData->ExchangeToValue); goldNum_2->setStringValue(str.getCString()); } UILabel* diamondNum_3 = dynamic_cast<UILabel*>(goldMarket->getWidgetByName("DiamondNum_3")); UILabelAtlas* goldNum_3 = dynamic_cast<UILabelAtlas*>(goldMarket->getWidgetByName("GoldNum_3")); pData = CMoneyMan::sharedInstance().getChgTempData(DiamondToGold_4); if (pData) { CCString str; str.initWithFormat("%d", pData->ExchangeFromValue); diamondNum_3->setText(str.getCString()); str.initWithFormat("%d",pData->ExchangeToValue); goldNum_3->setStringValue(str.getCString()); } //UILabel* diamondNum_4 = dynamic_cast<UILabel*>(goldMarket->getWidgetByName("DiamondNum_4")); //UILabelAtlas* goldNum_4 = dynamic_cast<UILabelAtlas*>(goldMarket->getWidgetByName("GoldNum_4")); //pData = CMoneyMan::sharedInstance().getChgTempData(DiamondToGold_5); //if (pData) //{ // CCString str; // str.initWithFormat("%d", pData->ExchangeFromValue); // diamondNum_4->setText(str.getCString()); // str.initWithFormat("%d",pData->ExchangeToValue); // goldNum_4->setStringValue(str.getCString()); //} }
void MainFooterLayer::menuItemClicked(CCObject* item) { int tag = ((CCNode*)item)->getTag(); if(tag == TAG_MENU_HOME) { selectAtIndex(mainlayer_ZhuYe); } else if(tag == TAG_MENU_MAOXIAN) { selectAtIndex(mainlayer_MaoXian); } else if(tag == TAG_MENU_JINGJI) { //竞技场8级开放 if (MyselfManager::getManager()->getMyZhuJueData()->getCurrentProperty().level < 8) { CCString temp; temp.initWithFormat("%s8%s%s", LFStrings::getValue("ZhuJue").c_str() , LFStrings::getValue("ji").c_str(), LFStrings::getValue("KaiQi").c_str()); UnblockWarnDialog *layer = UnblockWarnDialog::create(temp.getCString(), false); CCDirector::sharedDirector()->getRunningScene()->addChild(layer, 100); return; } selectAtIndex(mainlayer_JingJiChang_challenge); } else if(tag == TAG_MENU_HUODONG) { selectAtIndex(mainlayer_HuoDong); } else if(tag == TAG_MENU_STORE) { selectAtIndex(mainlayer_ShangDian); } }
void BPElevatorNode::setElevatorNumber(uint32_t eNumber) { m_iElevatorNumber = eNumber; CCString szTemp; szTemp.initWithFormat("%d", m_iElevatorNumber); m_pElevatorNumber->setString(szTemp.getCString()); }
void GameNewLinker::showPointPic() { CCSize visablesize = CCDirector::sharedDirector() -> getVisibleSize(); auto *pic = CCSprite::create("./Link/linkerNumber/linkerNumber_F.png"); pic -> setPosition(ccp(visablesize.width, visablesize.height/2)); int numAll = pointsCount; int num = numAll%10; int width = -80; std::vector<int>Number; while (1) { Number.push_back(num); numAll = ((numAll - num)/10); if (numAll <= 0) { break; } num = numAll%10; } CCString str; for (int i = 0; i < Number.size(); i++) { str.initWithFormat("./Link/linkerNumber/linkerNumber_%d.png", Number[i]); auto *pic1 = CCSprite::create(str.getCString()); pic1 -> setPosition(ccp(width, 50)); width -= 75; pic -> addChild(pic1); } this -> addChild(pic, 100); pic -> runAction(CCSequence::create(CCMoveBy::create(0.2, ccp(-visablesize.width/2 + 40, 0)),CCDelayTime::create(0.5),CCRemoveSelf::create(),NULL)); }
bool GameShare_Score::init() { if (!CCSprite::init()) { return false; } this->setContentSize(CCSize(245, 121)); score = 0; //背景图片 // CCSprite *scoreBgSprite = GameShare_Texture::sharedTexture()->GetSpriteByCCRect(akoopang_image, CCRect(694, 820, 245, 121)); mpBg = CCSprite::createWithSpriteFrameName("common/score_bg.png"); this->addChild(mpBg); scroeSprite = CCSprite::create(); this->addChild(scroeSprite); scroeSprite->setVisible(false); VEC_NUMFILENAME vecNumFileName; for (int i = 0; i < 10; ++i) { CCString str; str.initWithFormat("common/game_score_%d.png",i); vecNumFileName.push_back(str.getCString()); } mpCounterImage = CCounterImage::create(vecNumFileName,"common/game_score_dot.png"); mpCounterImage->setPositionY(-20); mpCounterImage->setCellNumberWidth(32); addChild(mpCounterImage); //mpCounterImage->setVisible(false); this->setScore(0); return true; }
void MainLayerZhuangBeiBaseBody::setEquipmentData(vector<Equipment*> equipmentVec, int flag, int specialEquip_GroupId) { if (equipmentVec.size() <= 0) { string infoStr = LFStrings::getValue("Zhuangbeibao_Empty"); UnblockWarnDialog* pDlg =UnblockWarnDialog::create(infoStr); CCDirector::sharedDirector()->getRunningScene()->addChild(pDlg, 300); } this->mEquipmentVec = equipmentVec; sortEquipment(flag); mTableView->reloadData(); { CCString temp; temp.initWithFormat("%s: %d/%u", LFStrings::getValue("Kongjian").c_str() , MyselfManager::getManager()->getAllEquipmentsWithOutEquipedOrChuanQi().size(), MAX_COUNTS_IN_KNAPSACK); if (m_zbTotalLabel) m_zbTotalLabel->setString(temp.getCString()); if (MyselfManager::getManager()->getAllEquipmentsWithOutEquipedOrChuanQi().size() >= MAX_COUNTS_IN_KNAPSACK) { if (m_zbTotalLabel) m_zbTotalLabel->setVisible(false); if (m_zbFenJieTiShi) m_zbFenJieTiShi->setVisible(true); if (m_zbFenJieMenu) m_zbFenJieMenu->setVisible(true); } else { if (m_zbTotalLabel) m_zbTotalLabel->setVisible(true); if (m_zbFenJieTiShi) m_zbFenJieTiShi->setVisible(false); if (m_zbFenJieMenu) m_zbFenJieMenu->setVisible(false); } } }
void GameWeekRewardLayer::BindingUIItems(CCObject *p) { CCString str; str.initWithFormat("%d%d",eNetMsgTypeMissionSys, eNetMsgMissionSysWeekRewardKind); CSJson::Value root = XQDate::sharedInstance().GetDate(str.getCString()); bool isShowBtn = false; for (int i = 0; i < root.size(); i ++) { CSJson::Value & val = root[i]; if (val["iscomplete"].asInt() == 1) { isShowBtn = true; } } ul = UILayer::create(); addChild(ul, 1); auto myLayout = static_cast<Layout*>(GUIReader::shareReader() -> widgetFromJsonFile("./CocoStudioResources/WeekRewardLayer.json")); ul -> addWidget(myLayout); UIPanel *myPanel = dynamic_cast<UIPanel*>(ul -> getWidgetByName("Panel_2")); myPanel -> addReleaseEvent(this, coco_releaseselector(GameWeekRewardLayer::touchWindow)); // bind ui images UIButton *btn = dynamic_cast<UIButton*>(ul -> getWidgetByName("LotteryBtn")); if (isShowBtn) { btn->disable(); btn->setVisible(false); } else { btn -> addReleaseEvent(this, coco_releaseselector(GameWeekRewardLayer::getWeekRewardBtnClick)); } //设置字体不被选中; }
void HelloWorld::setTextTips(CCSprite* bgSprite) { std::string str = "the item is on the "; int tag = bgSprite->getTag(); switch(tag) { case 1: str+="center of the bg (bg : 1)"; break; case 2: str+="the lower left corner of the bg (bg : 2)"; break; case 3: str+="the upper right corner of the bg (bg : 3)"; break; case 4: str+="the lower right corner of the bg (bg : 4)"; break; case 5: str+="center of the bg (bg : add)"; break; } m_itemTipsLabel->setString(str.c_str()); CCString num; num.initWithFormat("the number of background sprites : %d",m_bg->getNumBgSprite()); m_numBgLabel->setString(num.getCString()); }
cocos2d::CCString AMapStrategy::getUrl( int x, int y, int z ) { const char* pUrl = "http://webrd02.is.autonavi.com/appmaptile?x=%d&y=%d&z=%d&lang=zh_cn&size=1&scale=1&style=7"; CCString strUrl; strUrl.initWithFormat(pUrl,x,y,17-z); return strUrl; }
cocos2d::CCString GoogleSatelliteMapStrategy::getUrl( int x, int y, int z ) { char* pUrl = "http://khms.google.com/kh/v=129&src=app&x=%d&y=%d&z=%d&s="; CCString strUrl; strUrl.initWithFormat(pUrl,x,y,17-z); return strUrl; }
cocos2d::CCString GoogleVectorMapStrategy::getUrl( int x, int y, int z ) { char* pUrl = "http://mts.google.com/vt/lyrs=m@216000000&hl=zh-CN&src=app&x=%d&y=%d&z=%d&s="; CCString strUrl; strUrl.initWithFormat(pUrl,x,y,17-z); return strUrl; }
bool Scene_GameItem::onPackageFilter(void *pDataPkg) { CResponsePacket* pPkt = (CResponsePacket*)pDataPkg; unsigned int unMsgType = pPkt->getMsgType(); unsigned int unMsgCode = pPkt->getMsgCode(); int nResCode = pPkt->getResCode(); //网络数据传输完成 if (pPkt->getDataState() == eNetMsgDataStateComplete/* && nResCode == eNetMsgResCodeSucceed*/) { if (unMsgType == eNetMsgTypeIntensifySys) { if (unMsgCode == eNetMsgCodeIntensifySysLvUp) { this->initData(); sMGameStrengthen mStrength; if (int temp = CPlayerInfoMan::sharedInstance().getMStrengthenByGameTag(GameShare_Global::shareGlobal()->gameType, gameLayer_Strong->getTag(),mStrength)){ gameLayer_Strong->setItemLv(mStrength.strengthenlv); CCString str; str.initWithFormat(GET_STRING_CSV(1010000019), mStrength.currencyValue, "金币"); if (temp == 2) { str = GET_STRING_CSV(1010000025); gameLayer_Strong->setBtnUnClick(); } gameLayer_Strong->setItemCurrency(mStrength.currencyValue); } gameLayer_Strong->successLvUp(); } } ////好友系统 if (unMsgType == eNetMsgTypeFriendSys) { if (unMsgCode == eNetMsgFriendSysGetRankByGame) { GameLayerGameRank* task = GetDlgPtr(GameLayerGameRank); task->addSureCallbackFunc(this, coco_releaseselector(Scene_GameItem::pkBtnCallBack)); this->addChild(task, 1); } } //消息系统 if (unMsgType == eNetMsgTypeMsgSys) { if (unMsgCode == eNetMsgGetBePkInfo) { GameLayerChallenge* layer = GetDlgPtr(GameLayerChallenge); layer->addSureCallbackFunc(this, coco_releaseselector(Scene_GameItem::pkBtnCallBack)); this->addChild(layer,1); layer->setState(0); } } // if (unMsgType == eNetMsgTypePlayerSys) { if (unMsgCode == eNetMsgPlayerSysReduceEnergy) { gointoGameCallBack(NULL); } } } return true; }
void Scene_GameItem::equipSuperCallBack(cocos2d::CCObject *object) { UIButton* btn = (UIButton*)object; if (gameLayer_Strong) { gameLayer_Strong = NULL; } gameLayer_Strong = GameLayer_ItemStrong::create(); gameLayer_Strong->setSureCallbackFunc(this, callfuncO_selector(Scene_GameItem::equipBtnCallBack)); CCString equipName = ""; int equipLv = 0; CCString equipValue = ""; CCString equipDetail = ""; CCString equipImg = ""; //获取玩家的这款游戏的强化信息. sMGameStrengthen mStrength; if (int temp = CPlayerInfoMan::sharedInstance().getMStrengthenByGameTag(GameShare_Global::shareGlobal()->gameType, btn->getTag(),mStrength)) { equipLv = mStrength.strengthenlv; equipValue.initWithFormat("x%d", mStrength.currencyValue); equipName.initWithFormat("./CocoStudioResources/GameItemName/%d.png",mStrength.strengthenImg); equipDetail = mStrength.strengthenDetail; equipImg.initWithFormat("./CocoStudioResources/GameStrengthen/%d.png",mStrength.strengthenImg); if (temp == 2) { equipValue = GET_STRING_CSV(1010000025); gameLayer_Strong->setBtnUnClick(); } } CCString str; gameLayer_Strong->setItemInfo(equipDetail.getCString()); gameLayer_Strong->setItemImg(equipImg.getCString()); gameLayer_Strong->setItemLv(equipLv); gameLayer_Strong->setItemName(equipName.getCString()); gameLayer_Strong->setItemCurrency(mStrength.currencyValue); // gameLayer_Strong->setSureCallbackFunc(this, callfuncO_selector(Scene_GameItem::equipBtnCallBack)); gameLayer_Strong->setSureBtnTag(btn->getTag()); gameLayer_Strong->setTag(btn->getTag()); this->addChild(gameLayer_Strong,1); }
void GameNewLinker::drawLine_1(int m, int n, int t) { CCPoint first = spritelistNow[m] -> getPosition(); CCPoint second = spritelistNow[n] -> getPosition(); float x = first.x - second.x; float y = first.y - second.y; CCPoint point; int kind = t; if (t == StarIcon) { t = 4; } if (t == Box_5w) { t = 5; } //判断线的方向 bool wellDraw = false; if (x < 0 && y == 0) { wellDraw = true; point = CCPoint(spritelistNow[m] -> getPositionX()+spritelistNow[m]->getContentSize().width*size, spritelistNow[m] -> getPositionY() + spritelistNow[m]->getContentSize().height /2*size); } if (x > 0 && y == 0) { wellDraw = true; point = CCPoint(spritelistNow[m] -> getPositionX(), spritelistNow[m] -> getPositionY() + spritelistNow[m] -> getContentSize().height /2*size); } if (x == 0 && y < 0) { wellDraw = true; point = CCPoint(spritelistNow[m] -> getPositionX()+spritelistNow[m]->getContentSize().width/2*size, spritelistNow[m] -> getPositionY() + spritelistNow[m]->getContentSize().height*size); } if (x == 0 && y > 0) { wellDraw = true; point = CCPoint(spritelistNow[m] -> getPositionX()+spritelistNow[m]->getContentSize().width/2*size, spritelistNow[m] -> getPositionY()); } if (wellDraw) { CCString str; 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); lineNode -> addChild(line); lineTiem lineItem; lineItem.pic = line; lineItem.kind = kind; lineItem.beginIndex = m; lineItem.endIndex = n; linelist.push_back(lineItem); } }
void TanSuoLayer::refreshDisconverTime(unsigned int count, unsigned int tansuoCount) { //unsigned int iTotalCount = CS::getDiscoverLimitTimes(MyselfManager::getManager()->getMyZhuJueData()->getVipLevel()); CCLabelTTF *label = (CCLabelTTF*)mBg->getChildByTag(Tag_Label_CurNum); if (label) { CCString temp; temp.initWithFormat("%u", count); label->setString(temp.getCString()); } int xunBaoCount = CS::getDiscoverLimitTimes(MyselfManager::getManager()->getMyZhuJueData()->getVipLevel());//寻宝次数上限 if (m_nHadCount == xunBaoCount) { m_nRefreshTime = 360; } m_nHadCount = count; if (count < xunBaoCount) { schedule(SEL_SCHEDULE(&TanSuoLayer::refreshTime),1.0f); } if (tansuoCount >= MAX_TANSUOTIMES) { mBg->removeChildByTag(Tag_Label_Haixu); mBg->removeChildByTag(Tag_Label_ShengyuNum); mBg->removeChildByTag(Tag_Label_DianLiang); m_tHaixuTTF = NULL; CCLabelTTF *pTTF = (CCLabelTTF*)mBg->getChildByTag(Tag_Label_YiDianLiang); if (pTTF) { pTTF->removeFromParent(); } CCString* temp = CCString::create(LFStrings::getValue("XunBaoYiJing_DianLiang_String").c_str()); CCLabelTTF *yidianliangLabel = CCLabelTTF::create(temp->getCString(), fontStr_kaiti, m_nFontSize, CCSize(0,0), kCCTextAlignmentCenter); mBg->addChild(yidianliangLabel, 1, Tag_Label_YiDianLiang); //yidianliangLabel->setAnchorPoint(ccp(0,0.5)); yidianliangLabel->setPosition(ccp( mBg->getContentSize().width / 2, 44)); yidianliangLabel->setColor(fonColor_PuTong); } else { int shengyuTimes = MAX_TANSUOTIMES - tansuoCount; //CCString *str = CCString::createWithFormat("%s%d%s",LFStrings::getValue("XunBaoHaixu_String").c_str(),shengyuTimes,LFStrings::getValue("XunBaoDianLiang_String").c_str()); CCLabelTTF *usedNum = (CCLabelTTF*)mBg->getChildByTag(Tag_Label_Haixu); if (usedNum) { usedNum->setString(CCString::createWithFormat("%d",shengyuTimes)->getCString()); } } }
void HelloWorld::addBgSpriteCallback(CCObject*) { if(addBgSprite(5)) { m_addTipsLabel->setString("add background - success"); CCString num; num.initWithFormat("the number of background sprites : %d",m_bg->getNumBgSprite()); m_numBgLabel->setString(num.getCString()); } else m_addTipsLabel->setString("add background - failure"); }
void GameLayer_Menu::setInfoNum() { UIImageView* img = dynamic_cast<UIImageView*>(gameMenu->getWidgetByName("Email_RemindImg")); if (CPlayerInfoMan::sharedInstance().getPlayerInfo().sysInfoNum <= 0) { img->setVisible(false); }else{ img->setVisible(true); UILabel* label = dynamic_cast<UILabel*>(gameMenu->getWidgetByName("InfoLabel")); CCString str; str.initWithFormat("%d",CPlayerInfoMan::sharedInstance().getPlayerInfo().sysInfoNum); label->setText(str.getCString()); } }
CCSprite* MySelfInfoLayer::getSpriteByScore(long score, CCPoint p, int kind) { long temp = score; //位数,用于设置横坐标偏移量. int digit = 0; CCSprite* scroeSprite = CCSprite::create(); scroeSprite ->setPosition(p); while (temp>0 || (digit==0 && temp==0)) { int remainder = temp % 10; temp = temp/10; CCSprite *m_Sprite; CCRect rc; CCString str; if (kind == 1) str.initWithFormat("f_%d.png", remainder); else str.initWithFormat("m_%d.png", remainder); m_Sprite = CCSprite::createWithSpriteFrameName(str.getCString()); if(kind ==1) m_Sprite->setPosition(ccp((digit+(digit/3))*(-15), 0)); else m_Sprite->setPosition(ccp((digit+(digit))*(-20), 0)); scroeSprite->addChild(m_Sprite); scroeSprite -> setPosition(ccp(scroeSprite->getPositionX() - 6, scroeSprite->getPositionY())); digit++; } digit--; CCArray* array = scroeSprite->getChildren(); for (int i=0; i<array->count(); i++) { CCPoint point = ((CCSprite*)array->objectAtIndex(i))->getPosition(); point.x += (digit+(digit/3))*15.0; ((CCSprite*)array->objectAtIndex(i))->setPosition(point); } return scroeSprite; }
MCScript * MCScriptMaker::createScript(const char *aScriptPath) { MCScript *trigger = new MCScript; CCString *scriptPath; trigger->autorelease(); scriptPath = new CCString; scriptPath->initWithFormat("%s", aScriptPath); trigger->scriptPath_ = scriptPath; return trigger; }
static void dictionary_Value(CCDictionary * aDict, const cocos2d::ValueMap & value) { cocos2d::ValueMap::const_iterator beg = value.begin(); cocos2d::ValueMap::const_iterator end = value.end(); for (; beg != end; ++beg) { const std::string & key = (*beg).first; const cocos2d::Value & v = (*beg).second; if (v.getType() == Value::Type::MAP) { CCDictionary * d = new CCDictionary(); d->init(); dictionary_Value(d, v.asValueMap()); aDict->setObject(d, key); d->release(); } else if (v.getType() == Value::Type::VECTOR) { CCArray * a = new CCArray(); a->init(); array_Value(a, v.asValueVector()); aDict->setObject(a, key); a->release(); } else { CCString * str = new CCString(); if (v.getType() == Value::Type::DOUBLE) str->initWithFormat("%f", v.asDouble()); else str->initWithFormat("%s", v.asString().c_str()); aDict->setObject(str, key); str->release(); } } }
void MapCell::updateView(const char *mapName, const Size &gridScale) { int x = ((int)gloabIndex.x < 0 ? 0 : (int)gloabIndex.x); int y = ((int)gloabIndex.y < 0 ? 0 : (int)gloabIndex.y); String urlMapName; urlMapName.initWithFormat("%s%s/", url.c_str(), mapName); request->setUrl(urlMapName.getCString(), NULL); // 根据全局索引设置sprite String miniName; miniName.initWithFormat("MiniMaps/%s.png", mapName); Texture2D * texture = TextureCache::getInstance()->addImage(miniName.getCString()); Rect rect(gloabIndex.x * 32, texture->getContentSize().height - (gloabIndex.y + 1)* 32, 32, 32); int heightGird = texture->getContentSize().height * 8 / 256; int widthGird = texture->getContentSize().width * 8 / 256; CCString fileName; if (x >= 0 && y >= 0 && x <= widthGird - 1 && y <= heightGird - 1) { sprite = Sprite::createWithTexture(texture, rect); this->addChild(sprite); sprite->setAnchorPoint(ccp(0, 0)); sprite->setScaleX(gridScale.width); // 宽 sprite->setScaleY(gridScale.height);// 高 CCString str; str.appendWithFormat("LOGING %u %u", y, x); fileName.appendWithFormat("%u_%u.png", x, y); int index = x + (heightGird - y - 1) * widthGird; fileName.initWithFormat("0000%d.png", index); char buffer[10] = { 0 }; std::string temp = fileName.getCString(); for (int i = 8; i >= 0; i--) { buffer[i] = temp.back(); temp.pop_back(); } LabelTTF * info = LabelTTF::create(buffer, "Arial", 13); info->setPosition(ccp(128, 128)); this->addChild(info); // log("load picture %s\n",fileName.getCString()); request->addFile(buffer, new MapCellResourceCallback(this)); request->go(); request->release(); } else request->release(); }
void GameTakeRewardLayer::picRunAction() { for (int i = 0; i < myImgList.size(); i ++) { myImgList[i] -> stopAllActions(); } CCAnimation* pAni = CCAnimation::create(); CCString str; for (int i = 1; i <=2; i ++) { str.initWithFormat("./CocoStudioResources/takeReward/images/face_%d_%d.png",selectorPic, i); pAni->addSpriteFrameWithFileName(str.getCString()); } pAni -> setDelayPerUnit(0.12f); pAni -> setLoops(1); myImgList[selectorPic -1] -> runAction(CCRepeatForever::create(CCAnimate::create(pAni))); }
// 06-15 11:43:50.179: D/cocos2d-x debug info(1716): Get data from file(tabulation_armor_helmet_1.png) failed! MainLayerZhuangBeiBaseBody::MainLayerZhuangBeiBaseBody(ZhuangbeiXiangQingFrom from) { mFrom = from; mTableView = CCTableView::create(this, CCSizeMake(624,678)); addChild(mTableView); mTableView->setDirection(kCCScrollViewDirectionVertical); mTableView->setVerticalFillOrder(kCCTableViewFillTopDown); mTableView->setPosition(ccp(8,74)); mTableView->setDelegate(this); mFooterForPop = NULL; mClickedIdx = 0; BaseSprite *bar = BaseSprite::create("mianban_zhuangbeishuliang_bg.png"); addChild(bar, 10); bar->setPosition(ccp(320, 43)); CCString temp; temp.initWithFormat("%s: %d/%u", LFStrings::getValue("zhuangbei").c_str() , MyselfManager::getManager()->getAllEquipmentsWithOutEquipedOrChuanQi().size(), MAX_COUNTS_IN_KNAPSACK); m_zbTotalLabel = CCLabelTTF::create(temp.getCString(), fontStr_kaiti, 20); m_zbTotalLabel->setAnchorPoint(ccp(1, 0.5)); m_zbTotalLabel->setPosition(ccp(bar->getContentSize().width-20, bar->getContentSize().height/2)); bar->addChild(m_zbTotalLabel); //分解提示 m_zbFenJieTiShi = CCLabelTTF::create(LFStrings::getValue("ZBCountMax_GanKuaiQuFenJieBa").c_str(), fontStr_kaiti, 20); bar->addChild(m_zbFenJieTiShi); m_zbFenJieTiShi->setPosition(ccp(bar->getContentSize().width/2, bar->getContentSize().height/2)); m_zbFenJieTiShi->setColor(fonColor_JingGao); m_zbFenJieTiShi->setVisible(false); m_zbFenJieMenu = CCMenu::create(); bar->addChild(m_zbFenJieMenu); m_zbFenJieMenu->setPosition(ccp(0,0)); m_zbFenJieMenu->setVisible(false); CCMenuItemImage *fenjie = CCMenuItemImage::create( "mianban_zhuangbei_qufenjie.png", "mianban_zhuangbei_qufenjie_select.png", this, menu_selector(MainLayerZhuangBeiBaseBody::menuitemClicked_GotoFenJie)); m_zbFenJieMenu->addChild(fenjie); fenjie->setPosition(ccp(m_zbTotalLabel->getPositionX()-fenjie->getContentSize().width/2, m_zbTotalLabel->getPositionY())); if (mFrom != From_ZhuangBeiList) { m_zbFenJieMenu->removeFromParent(); } }
void PointsManager::AnihilationHappened(int numberOfBlocks, cocos2d::CCPoint spot) { // number of points that will be added depends upon the number of blocks that are being anihilated int addpoints = 0; // in case it's a power up if (numberOfBlocks == 1) {addpoints = 2;} // normal anihilation else if (numberOfBlocks == 3){addpoints = 10;} // 4-block anihilation else if (numberOfBlocks == 4){addpoints = 30;} // bigger anihiltion else if (numberOfBlocks == 5){addpoints = 60;} points += addpoints; // update number of points pointsToDisplay.initWithFormat("%i",points); pointsLabel->setCString(pointsToDisplay.getCString()); // create a flying number on the screen CCString flyingNumberString; flyingNumberString.initWithFormat("%i",addpoints); CCLabelBMFont* flyingNumber = CCLabelBMFont::create(flyingNumberString.getCString(),"Assets/badab.fnt"); flyingNumber->setColor(ccc3(0,0,0)); flyingNumber->setPosition(spot); //put some nice actions on the number CCAction* sequence = CCSequence::create(CCDelayTime::actionWithDuration(1.0), CCFadeOut::actionWithDuration(1.0f), CCCallFuncO::actionWithTarget(this,callfuncO_selector(PointsManager::DeleteTextCallback),flyingNumber), NULL); // add to node flyingNumber->runAction(sequence); flyingNumber->runAction(CCMoveBy::actionWithDuration(2.0f,ccp(0.0f,120.0f))); this->addChild(flyingNumber); if (isConnected) { // send update points to other player RakNet::BitStream BsOut; BsOut.Write((RakNet::MessageID)ID_GAME_NEW_POINTS); BsOut.Write((const char*)&points,sizeof(int)); player2->Send(&BsOut,HIGH_PRIORITY,RELIABLE_ORDERED,0,player2Adress,false); } }
void GameNewLinker::msgHanlde_GameTimeOut(CCObject* obj) { CTaskManProce(eDayTaskTypeShare_1, score); CTaskManProce(eDayTaskTypeShare_4, allbatter); CTaskManProce(eDayTaskTypeShare_5, scoreBy20); CTaskManProce(eDayTaskTypeShare_6, superModelTime); CTaskManProce(eDayTaskTypeShare_7, bigestBatter); CTaskManProce(eDayTaskTypeShare_8, boomCount); if (!CCUserDefault::sharedUserDefault()->getBoolForKey("P_1") && !CCUserDefault::sharedUserDefault()->getBoolForKey("P_2")&&!CCUserDefault::sharedUserDefault()->getBoolForKey("P_3")&&!CCUserDefault::sharedUserDefault()->getBoolForKey("P_4")) { CTaskManProceDt(eDayTaskTypeShare_9, 1); } int count = 0; CCString str; for (int i = 1; i <= 4; i++) { str.initWithFormat("P_%d", i); if (CCUserDefault::sharedUserDefault()->getBoolForKey(str.getCString())) { count ++; } } CTaskManProce(eDayTaskTypeShare_10, count); if (score == 0) { CTaskManProceDt(eDayTaskTypeShare_11, 1); } CTaskManProce(eDayTaskTypeShare_12, missNumber); if (score>= 50000 && boomCount == 0) { CTaskManProceDt(eDayTaskTypeShare_13, 1); } if (p_4_batter) { p_4_batter = false; CTaskManProceDt(eDayTaskTypeTK_76, 1); } if (CCUserDefault::sharedUserDefault() -> getBoolForKey("P_1")) { CTaskManProceDt(eDayTaskTypeTK_77, 1); } CTaskManProceDt(eDayTaskTypeTK_78, boxCount); CTaskManProceDt(eDayTaskTypeTK_79, easyListCount); CTaskManProceDt(eDayTaskTypeTK_80, starCount); CTaskManProce(eDayTaskTypeTK_81, rigthCount); this -> unscheduleAllSelectors(); GameShare_Scene::msgHanlde_GameTimeOut(obj); }