本文整理汇总了C++中CCString::initWithFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ CCString::initWithFormat方法的具体用法?C++ CCString::initWithFormat怎么用?C++ CCString::initWithFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCString
的用法示例。
在下文中一共展示了CCString::initWithFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SaveDate
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();
}
示例2: array_Value
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();
}
}
}
示例3: getSpriteByScore
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;
}
示例4: itemBtnCallBack
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());
}
示例5: init
/**
* 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);
}
示例6: setValue
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());
//}
}
示例7: menuItemClicked
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);
}
}
示例8: setElevatorNumber
void BPElevatorNode::setElevatorNumber(uint32_t eNumber)
{
m_iElevatorNumber = eNumber;
CCString szTemp;
szTemp.initWithFormat("%d", m_iElevatorNumber);
m_pElevatorNumber->setString(szTemp.getCString());
}
示例9: showPointPic
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));
}
示例10: init
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;
}
示例11: setEquipmentData
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);
}
}
}
示例12: BindingUIItems
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));
}
//设置字体不被选中;
}
示例13: setTextTips
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());
}
示例14: getUrl
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;
}
示例15: getUrl
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;
}