bool JunxianItem::initWithSize() { if (!SNSTableViewCellItem::init()) { return false; } ResourceManager::sharedInstance()->bindTexture("sgplayerinfolayer/sgplayerinfolayer.plist", RES_TYPE_LAYER_UI, sg_junxianlayer); bgSize = CCSizeMake(600, 125); // bgSize=CCSizeMake(skewing(300), skewing(65)); float viewWid = bgSize.width; float viewH = bgSize.height; CCScale9Sprite *frame2 = CCScale9Sprite::createWithSpriteFrameName("barrack_kuang.png"); frame2->setPreferredSize(CCSizeMake(viewWid, viewH)); this->addChild(frame2); // frame2->setPosition(spriteBg->getPosition()); CCSprite *frame2bg = CCSprite::createWithSpriteFrameName("barrack_kuangbg.png"); this->addChild(frame2bg, -1); frame2bg->setScaleX(viewWid/frame2bg->getContentSize().width); frame2bg->setScaleY(viewH/frame2bg->getContentSize().height); frame2bg->setPosition(frame2->getPosition()); const char* fontName = FONT_BOXINFO; const int fontsize = 26; condition = CCLabelTTF::create("", fontName, fontsize); condition->setAnchorPoint(ccp(0,0.5)); buff = CCLabelTTF::create(str_JunxianLayer_str2, fontName, fontsize,CCSizeMake(fontsize*11,fontsize*3),kCCTextAlignmentLeft,kCCVerticalTextAlignmentTop); buff->setAnchorPoint(ccp(0,1)); CCLabelTTF* hdtj = CCLabelTTF::create(str_JunxianLayer_str3, fontName, fontsize); hdtj->setPosition(ccp(-100,25)); this->addChild(hdtj); condition->setPosition(ccpAdd(hdtj->getPosition(),ccp(hdtj->getContentSize().width/2,0))); this->addChild(condition); CCLabelTTF* jxjc = CCLabelTTF::create(str_JunxianLayer_str4, fontName, fontsize); jxjc->setPosition(ccpAdd(hdtj->getPosition(),ccp(0,-32))); jxjc->setColor(ccYELLOW); this->addChild(jxjc); // buff->setPosition(ccp(0,0)); // buff->setString("sgadfsdafssfsafsafdfsafseagfdsfdsf"); buff->setPosition(ccpAdd(jxjc->getPosition(),ccp(jxjc->getContentSize().width/2,jxjc->getContentSize().height/2))); buff->setColor(ccYELLOW); this->addChild(buff); ////////// return true; }
// on "init" you need to initialize your instance bool GameScene::init() { if ( !CCLayer::init() ) { return false; } // 背景画像を設定する setBackGroundSprite(); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(GameScene::menuCloseCallback)); pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); CCMenu* pMenuClose = CCMenu::create(pCloseItem, NULL); pMenuClose->setPosition(CCPointZero); this->addChild(pMenuClose, 1); CCLabelTTF* pLabel = CCLabelTTF::create("GameScene", "Arial", 24); pLabel->setColor(ccc3((GLubyte)0,(GLubyte)0,(GLubyte)0)); pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); this->addChild(pLabel, 1); // 線引きのガイダンスを表示 int fontSize = CCEGLView::sharedOpenGLView()->getDesignResolutionSize().height/320.0f * 18; CCLabelTTF *label = CCLabelTTF::create("指でなぞったラインを CCMotionStreak で描画します", "Helvetica", /*fontSize*/ 24); label->setColor(ccc3((GLubyte)0,(GLubyte)0,(GLubyte)0)); label->setPosition(ccp(visibleSize.width / 2, visibleSize.height - label->getContentSize().height * 4)); this->addChild(label); this->setTouchEnabled(true); // タッチイベントを有効化 this->setTouchMode(kCCTouchesOneByOne); // シングルタッチ // CCSprite* pSprite = CCSprite::create("HelloWorld.png"); // pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // this->addChild(pSprite, 0); // 次の画面へ遷移するボタン CCMenuItemImage *pNextItem = CCMenuItemImage::create( "HelloWorld.png", "HelloWorld_02.png", this, menu_selector(GameScene::buttonOnClickCallBack)); pNextItem->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); CCMenu* pMenuNext = CCMenu::create(pNextItem, NULL); pMenuNext->setPosition(CCPointZero); this->addChild(pMenuNext, 0); return true; }
/** * 初始化函数 * @param enterLimit 进入限制 * @param baseBet 底注 */ void YJGameModeLabel::init(const char* enterLimit, const char* baseBet) { const float label_height = 30.0f ; ////////////////////////// 进入限制 /////////////////////// char entryfeeStr[30] ; sprintf(entryfeeStr, "进入限制:%s金币\0", enterLimit) ; CCLabelTTF* enterLimitLabel = CCLabelTTF::create(entryfeeStr, "font01.ttf", 20.0f) ; enterLimitLabel->setColor(ccc3(0, 0, 0)) ; enterLimitLabel->setAnchorPoint(ccp(0, 0)) ; enterLimitLabel->setPosition(ccp(0, label_height)) ; enterLimitLabel->setHorizontalAlignment(kCCTextAlignmentLeft) ; // 水平对齐方式 enterLimitLabel->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; // 垂直对齐方式 this->addChild(enterLimitLabel) ; ////////////////////////// 底注 ///////////////////////// char awardStr[30] ; sprintf(awardStr, " 底注:%s金币\0", baseBet) ; CCLabelTTF* baseBetLabel = CCLabelTTF::create(awardStr, "font01.ttf", 20.0f) ; baseBetLabel->setColor(ccc3(0, 0, 0)) ; baseBetLabel->setAnchorPoint(ccp(0, 0)) ; baseBetLabel->setPosition(ccp(0, 0)) ; baseBetLabel->setHorizontalAlignment(kCCTextAlignmentLeft) ; // 水平对齐方式 baseBetLabel->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; // 垂直对齐方式 this->addChild(baseBetLabel) ; float width = enterLimitLabel->getContentSize().width > baseBetLabel->getContentSize().width?enterLimitLabel->getContentSize().width:baseBetLabel->getContentSize().width ; this->setContentSize(CCSizeMake(width, 2*label_height)) ; }
void RWLViewDBSource::ReadLgCell(std::string asHead, LogicCell* algc) { if(0 == algc->miType){ CCLabelTTF* tlt = CCLabelTTF::create((asHead+algc->msText).c_str(), FNT_UI_LABEL, 24,CCSize(rw,0), kCCTextAlignmentLeft); tlt->retain(); m_plength.push_back(tlt->getContentSize().height); CCLog("+++++++%f", tlt->getContentSize().height); m_height += tlt->getContentSize().height; data->addObject(tlt); asHead += " "; return; } for(std::vector<LogicCell*>::iterator it = algc->mvChilds.begin(); it != algc->mvChilds.end(); ++it){ if((*it)->miType == 0){ asHead += " "; break; } } for(std::vector<LogicCell*>::iterator it = algc->mvChilds.begin(); it != algc->mvChilds.end(); ++it){ ReadLgCell(asHead.c_str(), *it); } }
void WordTreeScene::updatePhysics(Word* word) { cpShape* shape = word->getShape(); if( shape!=NULL ) { cpSpaceRemoveShape(ChipmunkManager::getInstance()->getSpace(), shape); cpShapeDestroy(shape); word->setShape(NULL); } cpBody* body = word->getBody(); if( body!=NULL ) { cpSpaceRemoveBody(ChipmunkManager::getInstance()->getSpace(), body); cpBodyDestroy(body); word->setBody(NULL); } CCLabelTTF* targetLabel = word->getLabel(); CCPoint pos = targetLabel->getPosition(); CCSize contentSize = targetLabel->getContentSize(); // init body body = cpBodyNew(1, INFINITY); body->p = cpv(targetLabel->getPosition().x, targetLabel->getPosition().y); cpSpaceAddBody(ChipmunkManager::getInstance()->getSpace(), body); float size = MAX(targetLabel->getContentSize().width, targetLabel->getContentSize().height); shape = cpBoxShapeNew(body, size+size*0.3f, size+size*0.3f); cpSpaceAddShape(ChipmunkManager::getInstance()->getSpace(), shape); word->setBody(body); word->setShape(shape); }
LayerChanToast::LayerChanToast(string message){ vector<string> lstRegex; for( int i = 1; i <= 16; i++ ){ lstRegex.push_back( CCString::createWithFormat("(%d)", i)->getCString() ); } this->setAnchorPoint(ccp(0, 0)); // text cocos2d::ui::RichText* label = cocos2d::ui::RichText::create(); label->setAnchorPoint(ccp(0, 0)); label->setPosition(ccp(0, HEIGHT_DESIGN / 3.5)); vector<string> lstContents = mUtils::splitStringByListRegex(message, lstRegex); int wLabel = 0, hLabel = 0; for( int i = 0; i < lstContents.size(); i++ ){ bool check = false; int j = 0; for( j = 0; j < lstRegex.size(); j++ ) if( lstRegex.at(j) == lstContents.at(i) ){ check = true; break; } if( check ){ CCArmature *armature = CCArmature::create(CCString::createWithFormat("onion%d", 1)->getCString()); armature->getAnimation()->playByIndex(j); cocos2d::ui::RichElementCustomNode* recustom = cocos2d::ui::RichElementCustomNode::create(1, ccWHITE, 255, armature); label->pushBackElement(recustom); wLabel += 50; hLabel = 55; }else{ CCLabelTTF *l = CCLabelTTF::create(lstContents.at(i).c_str(), "Arial", 16); l->setColor(ccc3(204, 16, 85)); cocos2d::ui::RichElementText* re1 = cocos2d::ui::RichElementText::create(1, ccWHITE, 255, lstContents.at(i).c_str(), "Arial", 16); label->pushBackElement(re1); wLabel += l->getContentSize().width; hLabel = hLabel > 50 ? 55 : l->getContentSize().height; } } this->addChild(label, 1, 0); CCSize sizeDesign = CCSize(169, 30); CCSpriteBatchNode *batchNode = CCSpriteBatchNode::create("chats/framechat_a.png"); CCScale9Sprite *blocks = CCScale9Sprite::create(); blocks ->updateWithBatchNode(batchNode , CCRect(0, 0, sizeDesign.width, sizeDesign.height), false, CCRect(10, 10, sizeDesign.width - 20, sizeDesign.height - 20)); CCSize size = CCSizeMake(wLabel + 10, hLabel + 5); blocks ->setContentSize(size); blocks->setAnchorPoint(ccp(0.5, 0.5)); blocks->setPosition(ccp(label->getPositionX() + wLabel / 2, label->getPositionY() + hLabel / 2)); blocks->setColor(ccc3(84, 81, 69)); blocks->setOpacity(200); this->setPosition(ccp((WIDTH_DESIGN - size.width) / 2, 100)); // add this->addChild(blocks); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if( !CCLayer::init())//RGBA { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getWinSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCSize winsize = CCDirector::sharedDirector()->getWinSize(); /* CCMenuItemImage *pNewGame = CCMenuItemImage::create("newgame.png", "newgame.png", this, menu_selector(HelloWorld::menuCloseCallback)); CCMenu *pMenu = CCMenu::create(pNewGame); pMenu->setPosition(ccp(winsize.width/2, pMenu->getContentSize().height)); this->addChild(pMenu);*/ CCLabelTTF* pLabel = CCLabelTTF::create("Brick Breaker", "Syncopate", 36); // position the label on the center of the screen pLabel->setPosition(ccp(origin.x + winsize.width/2, origin.y + winsize.height - pLabel->getContentSize().height)); pLabel->setColor(ccORANGE); // add the label as a child to this layer this->addChild(pLabel, 1); CCLabelTTF* pLabel2 = CCLabelTTF::create("by David Grayson", "Syncopate", 30); // position the label on the center of the screen pLabel2->setPosition(ccp(origin.x + winsize.width/2, origin.y + winsize.height - (pLabel->getContentSize().height)*2)); pLabel2->setColor(ccORANGE); // add the label as a child to this layer this->addChild(pLabel2, 1); new_game_button = CCSprite::create("newgame2.png"); //new_game_button->setScaleX(visibleSize.width/1000); //new_game_button->setScaleY(visibleSize.height/1000); new_game_button->setScale(1.0f); new_game_button->setPosition(ccp(winsize.width/2, new_game_button->getContentSize().height*4)); this->addChild(new_game_button); option_button = CCSprite::create("options2.png"); //option_button->setScaleX(visibleSize.width/1000); //option_button->setScaleY(visibleSize.height/1000); option_button->setScale(1.0f); option_button->setPosition(ccp(winsize.width/2, option_button->getContentSize().height*2)); this->addChild(option_button); this->setTouchEnabled(true); return true; }
bool GameOverLayer::init() { bool bRet = false; do { CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint visibleOrigin = CCDirector::sharedDirector()->getVisibleOrigin(); CCSprite* gameOverBg = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("gameover.png")); gameOverBg->setPosition(ccp(visibleOrigin.x + visibleSize.width/2, visibleOrigin.y + visibleSize.height/2)); this->addChild(gameOverBg); passScoreItem=CCLabelBMFont::create("0", "font/font.fnt"); passScoreItem->setColor(ccc3(143, 146, 147)); //灰白色 passScoreItem->setAnchorPoint(ccp(0.5, 0.5)); passScoreItem->setPosition(ccp(visibleOrigin.x + visibleSize.width/2, visibleOrigin.y + visibleSize.height/2)); CCString* strScore = CCString::createWithFormat("%d", this->thisTimeGetscore); //格式化为字符串 passScoreItem->setString(strScore->m_sString.c_str()); //从CCString中获得char*,更新分数 this->addChild(passScoreItem); CCLabelTTF* highestScoreItem = CCLabelTTF::create("", "Arial", 24); highestScoreItem->setColor(ccc3(3, 3, 3)); //黑色 CCString* highestScore=CCString::createWithFormat("highestScore:%d", GameOverLayer::highestHistoryScore); highestScoreItem->setString(highestScore->m_sString.c_str()); highestScoreItem->setPosition(ccp(visibleOrigin.x + highestScoreItem->getContentSize().width/2, visibleOrigin.y + visibleSize.height - highestScoreItem->getContentSize().height)); this->addChild(highestScoreItem); if (thisTimeGetscore > GameOverLayer::highestHistoryScore) { CCUserDefault::sharedUserDefault()->setIntegerForKey("HighestScore", thisTimeGetscore); //修改存档 CCUserDefault::sharedUserDefault()->flush(); GameOverLayer::highestHistoryScore = thisTimeGetscore; //最高分重新设定 } CCDelayTime* delay = CCDelayTime::create(1.0f); CCScaleTo* scaleBig = CCScaleTo::create(1.0f, 3.0f); CCScaleTo* scaleLittle = CCScaleTo::create(0.3f, 2.0f); CCFiniteTimeAction* sequence = CCSequence::create(delay, scaleBig, scaleLittle, NULL); passScoreItem->runAction(sequence); CCSprite* normalPause = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_finish.png")); CCSprite* pressedPause = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_finish.png")); CCMenuItemImage* restartGame = CCMenuItemImage::create(); restartGame->initWithNormalSprite(normalPause, pressedPause, NULL, this, menu_selector(GameOverLayer::restartGame)); restartGame->setPosition(ccp(visibleOrigin.x + visibleSize.width - normalPause->getContentSize().width, visibleOrigin.y + normalPause->getContentSize().height)); CCMenu* menu = CCMenu::create(restartGame, NULL); menu->setPosition(CCPointZero); this->addChild(menu, 10); bRet = true; }while(0); return bRet; }
CCSize ListViewLayer::tableCellSizeForIndex(CCTableView *table,unsigned int idx) { const char * str = aVect[idx].c_str(); CCLabelTTF *pLabel = CCLabelTTF::create(str, "Arial", 20.0,CCSizeMake(table->getContentSize().width, 0), kCCTextAlignmentLeft); CCLOG("%f",pLabel->getContentSize().height); return pLabel->getContentSize(); }
void AchievementNotification::showImmediately(Achievement a) { mShowing = true; CCTexture2D* tex = CCTextureCache::sharedTextureCache()->textureForKey(fileName.c_str()); if (tex == NULL) { tex = CCTextureCache::sharedTextureCache()->addImage(fileName.c_str()); } CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCScale9Sprite* pBoard = CCScale9Sprite::create(CCRectMake(tex->getContentSize().width/2, 0, 2, tex->getContentSize().height), fileName.c_str()); addChild(pBoard,0,Tag_Board); pBoard->setPosition(ccp(winSize.width/2,winSize.height + pBoard->getContentSize().height) ); CCSprite* pJinBei = CCSprite::create(ResManager::getManager()->getFilePath(g_public+"CJ_icon_jiangbei.png").c_str()); pBoard->addChild(pJinBei, 1); pJinBei->setPosition(ccp(pJinBei->getContentSize().width, pBoard->getContentSize().height/2)); CCLabelTTF* pName = CCLabelTTF::create(a.name.c_str(), fontStr_KlavikaBold, 40); pName->setColor(fontColor_Acheivement_TTF); CCSprite* pIcon = CCSprite::create(ResManager::getManager()->getFilePath(g_public+"CJ_icon_wancheng.png").c_str()); int x = pName->getContentSize().width + pIcon->getContentSize().width - 420; if (x > 0) { pBoard->setContentSize(ccp(pBoard->getContentSize().width+x, pBoard->getContentSize().height)); } pBoard->addChild(pName); int xoffset = 10; pName->setPosition(ccp(pBoard->getContentSize().width/2 + pIcon->getContentSize().width/2 + xoffset, pBoard->getContentSize().height/2)); pBoard->addChild(pIcon); pIcon->setPosition(ccp(pName->getPositionX() - pName->getContentSize().width/2 - pIcon->getContentSize().width/2 - xoffset, pName->getPositionY())); Achievement* achievementCopy = new Achievement(a); // *achievementCopy = a; temp_Must_Delete.insert(temp_Must_Delete.end(),achievementCopy); pBoard->runAction(CCSequence::create( CCMoveTo::create(0.5f,ccp(pBoard->getPositionX(),winSize.height-pBoard->getContentSize().height/2)), CCDelayTime::create(0.1f), CCCallFuncND::create(this,SEL_CallFuncND(&AchievementNotification::boardShowing),achievementCopy), CCDelayTime::create(1.3f), CCMoveTo::create(0.2f,ccp(pBoard->getPositionX(),winSize.height+pBoard->getContentSize().height)), CCFadeTo::create(0.1f,0), CCCallFuncN::create(this,SEL_CallFuncN(&AchievementNotification::boardShowEnd)),NULL)); createPar(ccp(winSize.width/2,winSize.height),parFileName.c_str(),pBoard->getContentSize().width * 1.2f,pBoard->getContentSize().height); Music::sharedMusicPlayer()->playEffectSound("achievement.wav"); CCLog("AchievementNotification::showImmediately name = %s" ,a.name.c_str()); }
bool HSGoldInadequateDialog::InitDialog() { CCSprite* pBackground = CCSprite::create("Image/SelectChannel/goumaijinbidikuang.png"); pBackground->setPosition(ccp(307,480)); this->addChild(pBackground); CCSprite* pGoldFrame = CCSprite::create("Image/SelectChannel/Mingziditu.png"); pGoldFrame->setPosition(ccp(236,202)); pBackground->addChild(pGoldFrame); CCSprite* pMoneyFrame = CCSprite::create("Image/SelectChannel/Mingziditu.png"); pMoneyFrame->setPosition(ccp(520,202)); pBackground->addChild(pMoneyFrame); const message::PropInfoData* pPropInfodata = HS_GAME_CACHE()->GetPropInfoData(); for (int i =0;i<pPropInfodata->buygoldlist_size();++i) { int temp = pPropInfodata->buygoldlist(i).gold_number(); if ((int)m_buyGold.gold_number() < temp) { m_buyGold = pPropInfodata->buygoldlist(i); } if (temp > HS_GAME_CACHE()->GetGold()) { m_buyGold = pPropInfodata->buygoldlist(i); break; } } CCLabelTTF* pGoldTTF = CCLabelTTF::create(CCString::createWithFormat("%d",m_buyGold.gold_number())->getCString(),HS_FONT_HuaKang,36.f); pGoldTTF->setAnchorPoint(HS_ANCHOR_L_CENTER); pGoldTTF->setPosition(ccp(0,pGoldTTF->getContentSize().height - pGoldTTF->getFontSize() / 2.f)); pGoldFrame->addChild(pGoldTTF); CCLabelTTF* pMoneyTTF = CCLabelTTF::create(CCString::createWithFormat("%d",m_buyGold.money())->getCString(),HS_FONT_HuaKang,36.f); pMoneyTTF->setAnchorPoint(HS_ANCHOR_L_CENTER); pMoneyTTF->setPosition(ccp(0,pMoneyTTF->getContentSize().height - pMoneyTTF->getFontSize() / 2.f)); pMoneyFrame->addChild(pMoneyTTF); CCMenuItem* pGoRoomItem = CCMenuItemImage::create("Image/SelectChannel/dibeilvchang_01.png","Image/SelectChannel/dibeilvchang_02.png",this,menu_selector(HSGoldInadequateDialog::Call_GoRoom)); pGoRoomItem->setPosition(ccp(169,322)); this->PushMenu(pGoRoomItem); CCMenuItem* pBuyItem = CCMenuItemImage::create("Image/SelectChannel/goumai_01.png","Image/SelectChannel/goumai_02.png",this,menu_selector(HSGoldInadequateDialog::Call_Buy)); pBuyItem->setPosition(ccp(456,322)); this->PushMenu(pBuyItem); return true; }
CCSprite* CreditsScreen::createPerson(const std::string& name, const std::string& twitterLink, const std::string& fbLink) { const float iconSize = 32; bool useTwitter = !twitterLink.empty(); bool useFB = !fbLink.empty(); CCSprite* person = CCSprite::create(); CCLabelTTF* nameLabel = CCLabelTTF::create(name.c_str(), default_font.c_str(), FONT_SIZE_PERSON); nameLabel->setPositionX(nameLabel->getContentSize().width / 2); float totalWidth = nameLabel->getContentSize().width; float totalHeight = MAX(nameLabel->getContentSize().height, iconSize); if(useTwitter || useFB){ totalWidth += PADDING_AFTER_NAME; } if(useTwitter){ totalWidth += iconSize + PADDING_PERSON; urls.push_back(twitterLink); Button* twitterButton = ButtonFactory::imageButton(TWITTER_ICON_INACTIVE, TWITTER_ICON_PRESSED, new Handler(this, callfuncD_selector(CreditsScreen::openURL), (void*)(urls.size() - 1)), BUTTON_PRIORITY); twitterButton->setPositionX(nameLabel->getPositionX() + totalWidth - iconSize - nameLabel->getContentSize().width/2); twitterButton->setPositionY(totalHeight / 2); person->addChild(twitterButton); } if(useFB) { totalWidth += iconSize + PADDING_PERSON; urls.push_back(fbLink); Button* fbButton = ButtonFactory::imageButton(FB_ICON_INACTIVE, FB_ICON_PRESSED, new Handler(this, callfuncD_selector(CreditsScreen::openURL), (void*)(urls.size() - 1)), BUTTON_PRIORITY); fbButton->setPositionX(nameLabel->getPositionX() + totalWidth - iconSize - nameLabel->getContentSize().width/2); fbButton->setPositionY(totalHeight / 2); person->addChild(fbButton); } person->setContentSize(CCSizeMake(totalWidth, totalHeight)); nameLabel->setPositionY(totalHeight / 2); person->addChild(nameLabel); return person; }
void SwarmGame::createDamageIndicator(const EntitySprite& es) { int damageTaken = es.m_entity->mobileStats().lastReducedHitPoints(); if ( damageTaken ) { CCPoint startingPos( es.m_sprite->getPosition().x + es.m_sprite->getContentSize().width/2, es.m_sprite->getPosition().y + es.m_sprite->getContentSize().height ); std::stringstream ss; CCLabelTTF* lblDmg = NULL; ss << (damageTaken < 0 ? "+" : "-") << damageTaken; lblDmg = CCLabelTTF::labelWithString(ss.str().c_str(), "Arial", 12); lblDmg->setColor( ccc3(255, 0, 0) ); startingPos.x -= lblDmg->getContentSize().width/2; lblDmg->setPosition( startingPos ); lblDmg->setAnchorPoint( ccp(0,0) ); m_mapLayer->addChild(lblDmg); CCSequence* floater = CCSequence::actionOneTwo( CCMoveTo::actionWithDuration( 1.0f, CCPoint( startingPos.x, startingPos.y + 50 ) ), CCCallFuncN::actionWithTarget( this, callfuncN_selector(SwarmGame::onDamageFloaterDone) ) ); lblDmg->runAction( floater ); es.m_entity->mobileStats().reset(); // if the sprite is taking damage, then colour it red es.m_sprite->setColor(ccc3(255, 128, 128)); } else { // if not damage is taken, reset the tint es.m_sprite->setColor(ccc3(255, 255, 255)); } }
bool CCLayer2::init() { bool bRet=false; do { CC_BREAK_IF(!CCLayer::init()); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCLabelTTF* pLabel = CCLabelTTF::create("Hello Layer2", "Arial", 30); // position the label on the center of the screen pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); // add the label as a child to this layer this->addChild(pLabel, 1); // add "HelloWorld" splash screen" CCSprite* pSprite = CCSprite::create("HelloWorld.png"); pSprite->setScale(0.8); // position the sprite on the center of the screen pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(pSprite, 0); bRet=true; } while (0); return bRet; }
// on "init" you need to initialize your instance bool HelloWorld::init() { if ( !CCLayer::init() ) { return false; } CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); pCloseItem->setPosition(ccpAdd(VisibleRect::rightBottom(), ccp(-pCloseItem->getContentSize().width/2, pCloseItem->getContentSize().height/2))); CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", SCALE_FACTOR * 24); pLabel->setPosition(ccpAdd(VisibleRect::top(), ccp(0, -pLabel->getContentSize().height))); this->addChild(pLabel, 1); CCSprite* pSprite = CCSprite::create("HelloWorld.png"); pSprite->setPosition(VisibleRect::center()); this->addChild(pSprite, 0); CCSprite *pLogoSprite = CCSprite::create("icon.png"); pLogoSprite->setAnchorPoint( ccp(0, 0.5) ); pLogoSprite->setPosition(ccpAdd(VisibleRect::left(), ccp(50, 0))); this->addChild(pLogoSprite, 0); return true; }
// on "init" you need to initialize your instance bool HelloOgre::init(){ if ( !CCLayer::init() ){ return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCSprite* pSprite = CCSprite::create("HelloWorld.png"); tAssertm( pSprite, "HelloWorld.png" ); pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); pSprite->setScale( 0.1 ); this->addChild(pSprite, 0); CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloOgre::menuCloseCallback)); pCloseItem->setPosition( ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); CCLabelTTF* pLabel = CCLabelTTF::create("Hello Ogre", "Arial", TITLE_FONT_SIZE); pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); this->addChild(pLabel, 1); initOgre(); createManual(); scheduleUpdate(); return true; }
void RichText::handleTextRenderer(const char *text, const char *fontName, float fontSize, const ccColor3B &color, GLubyte opacity) { CCLabelTTF* textRenderer = CCLabelTTF::create(text, fontName, fontSize); float textRendererWidth = textRenderer->getContentSize().width; _leftSpaceWidth -= textRendererWidth; if (_leftSpaceWidth < 0.0f) { float overstepPercent = (-_leftSpaceWidth) / textRendererWidth; std::string curText = text; int stringLength = _calcCharCount(text);; int leftLength = stringLength * (1.0f - overstepPercent); std::string leftWords = curText.substr(0, leftLength); std::string cutWords = curText.substr(leftLength, curText.length()-1); if (leftLength > 0) { CCLabelTTF* leftRenderer = CCLabelTTF::create(leftWords.substr(0, leftLength).c_str(), fontName, fontSize); leftRenderer->setColor(color); leftRenderer->setOpacity(opacity); pushToContainer(leftRenderer); } addNewLine(); handleTextRenderer(cutWords.c_str(), fontName, fontSize, color, opacity); } else { textRenderer->setColor(color); textRenderer->setOpacity(opacity); pushToContainer(textRenderer); } }
bool Toast::init(const char* string ,int duration) { bool ret = false; do { CC_BREAK_IF(!CCSprite::init()); //CCLabelTTF *label = CCLabelTTF::create(string,"Arial", 28); CCLabelTTF *label = CCLabelTTF::create(string, "Arial", 28, CCSizeMake(0,45), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter); label->setColor(ccc3(255,255,255)); Scale9Sprite* c9s = Scale9Sprite::create("res/Toast/toast_bg.png"); CCSize labelSize = label->getContentSize(); label->setPosition(ccp((labelSize.width + 100)/2, 45/2)); label->setAnchorPoint(ccp(0.5,0.5)); CCSize c9sSize = CCSizeMake(labelSize.width + 100, 45); c9s->setContentSize(c9sSize); addChild(c9s); addChild(label); c9s->setPosition(Vec2::ZERO); //2.2.6ʹÓÃCCPointZero c9s->setAnchorPoint(Vec2::ZERO); setContentSize(c9s->getContentSize()); m_Duration = duration; setVisible(false); setScaleX(0); ret = true; } while (0); return ret; }
LFToast::LFToast(string msg,float during) { CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCScale9Sprite* base = CCScale9Sprite::create("toast.png"); CCLabelTTF* lable = CCLabelTTF::create( msg.c_str(), fontStr_kaiti, 30, CCSize(base->getContentSize().width - 10,0), kCCTextAlignmentLeft); lable->setAnchorPoint(ccp(0,0.5f)); addChild(base); base->setContentSize(CCSizeMake(base->getContentSize().width,lable->getContentSize().height + 20)); base->setOpacity(0); base->addChild(lable); lable->setPosition(ccp(10,base->getContentSize().height/2)); base->setPosition(ccp(visibleSize.width/2,base->getContentSize().height + 20)); base->runAction(CCSequence::create( CCFadeTo::create(0.2f,255), CCDelayTime::create(during), CCFadeTo::create(0.1f,0), CCCallFuncN::create(this,SEL_CallFuncN(&LFToast::removeToast)), NULL )); }
ScreenSizeTest::ScreenSizeTest(void) { Random::initRandomSeed(); CCLOG("1randomFloat=%f", Random::randomFloat(-2.4f, 6.6f)); CCLOG("2randomFloat=%f", Random::randomFloat(-2.4f, 6.6f)); //文本 CCSprite* bg = CCSprite::create("bg.jpg"); bg->setAnchorPoint(ccp(.5f, .5f)); this->addChild(bg); bg->setPosition(ScreenUtil::getCenter()); CCLOG("getScreenWidth%f", ScreenUtil::getScreenWidth()); CCLOG("getScreenHeight%f", ScreenUtil::getScreenHeight()); CCLabelTTF* label = CCLabelTTF::create("hello world", "隶书", 30); this->addChild(label); label->setPosition(ccp(ScreenUtil::getLeft() + label->getContentSize().width / 2, ScreenUtil::getTop() - label->getContentSize().height / 2)); CCLOG("isSymbolWord %i", StringUtil::isSymbolWord("\n")); CCLOG("isAlphabetWord %i", StringUtil::isAlphabetWord("aaa")); CCLOG("isNumberWord %i", StringUtil::isNumberWord("158")); int pos = StringUtil::indexOf("阿斯顿", "斯"); CCLOG("pos: %d", pos); string str = "阿斯斯顿"; StringUtil::replace(str, "斯斯", "****"); CCLOG("str: %s", str.c_str()); string str1 = ",,"; string str2 = ","; size_t pos2 = str1.find(str2); CCLOG("pos: %d", pos2); }
bool TextFieldTTFActionTest::onTextFieldDeleteBackward(CCTextFieldTTF * pSender, const char * delText, int nLen) { // create a delete text sprite aScut do some action CCLabelTTF * label = CCLabelTTF::create(delText, FONT_NAME, FONT_SIZE); this->addChild(label); // move the sprite to fly out CCPoint beginPos = pSender->getPosition(); CCSize textfieldSize = pSender->getContentSize(); CCSize labelSize = label->getContentSize(); beginPos.x += (textfieldSize.width - labelSize.width) / 2.0f; CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCPoint endPos(- winSize.width / 4.0f, winSize.height * (0.5 + (float)raScut() / (2.0f * RAScut_MAX))); float duration = 1; float rotateDuration = 0.2f; int repeatTime = 5; label->setPosition(beginPos); CCAction * seq = CCSequence::create( CCSpawn::create( CCMoveTo::create(duration, endPos), CCRepeat::create( CCRotateBy::create(rotateDuration, (raScut()%2) ? 360 : -360), repeatTime), CCFadeOut::create(duration), 0), CCCallFuncN::create(this, callfuncN_selector(TextFieldTTFActionTest::callbackRemoveNodeWhendidAction)), 0); label->runAction(seq); return false; }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24); // position the label on the center of the screen pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); // add the label as a child to this layer this->addChild(pLabel, 1); // add "HelloWorld" splash screen" CCSprite* pSprite = CCSprite::create("HelloWorld.png"); // position the sprite on the center of the screen pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(pSprite, 0); // enable standard touch this->setTouchEnabled(true); return true; }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24); // position the label on the center of the screen pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); // add the label as a child to this layer this->addChild(pLabel, 1); CCRect rect1(133, 333, 42, 46); CCScale9Sprite* btnNormal = CCScale9Sprite::create("char_bluelight.png",rect1); CCScale9Sprite* btnDown = CCScale9Sprite::create("char_bluelight.png",rect1); CCControlButton* controlBtn = CCControlButton::create(btnNormal); controlBtn->setBackgroundSpriteForState(btnDown, CCControlStateSelected); controlBtn->setPosition(ccp(visibleSize.width/2, visibleSize.height/2)); controlBtn->setPreferredSize(CCSize(60, 50)); controlBtn->addTargetWithActionForControlEvents(this, cccontrol_selector(HelloWorld::touchDownAction), CCControlEventTouchDown); this->addChild(controlBtn); return true; }
// on "init" you need to initialize your instance bool TestLayer::init() { bool bRet = false; do { ////////////////////////////////////////////////////////////////////////// // super init first ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // add your codes below... ////////////////////////////////////////////////////////////////////////// this->setTouchEnabled(true); CCArray* itemsArray = CCArray::create(); CCMenuItemFont* item = CCMenuItemFont::create("Back", this, menu_selector(TestLayer::menuCallback)); item->setTag(1); itemsArray->addObject(item); CCMenu* menu = CCMenu::createWithArray(itemsArray); menu->alignItemsVertically(); this->addChild(menu); // menu->setPosition(item->getContentSize().width, CCDirector::sharedDirector()->getWinSize().height - item->getContentSize().height/2); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); menu->setPosition(20, winSize.height - 50); std::string message = this->initTest(); CCSize s = CCDirector::sharedDirector()->getWinSize(); float fontSize = 14; if(s.height > 1024) { fontSize = 34; } CCLabelTTF* label = CCLabelTTF::create(message.c_str(), "Arial", fontSize); CCSize labelSize = label->getContentSize(); label->setPosition(ccp(s.width/2, labelSize.height)); this->addChild(label, -2); bRet = true; } while (0); return bRet; }
bool HomeScene::init() { // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize size = CCDirector::sharedDirector()->getWinSize(); CCSprite* bgSpr = CCSprite::create("home_bg.png"); bgSpr->setAnchorPoint(ccp(0, 0)); bgSpr->setPosition( ccp(0, size.height-960) ); this->addChild(bgSpr, -1, 0); HomeLayer* layer = new HomeLayer(); layer->initWithDelegate(this); this->addChild(layer); //下导航区域 CCMenuItemImage *bu01 = CCMenuItemImage::create("zhuye.png", "zhuye.png", this, menu_selector(HomeScene::menuItemCallBack)); bu01->setTag(1); bu01->setPosition(ccp(60, 0)); CCMenuItemImage *bu02 = CCMenuItemImage::create("chengshi.png", "chengshi.png", this, menu_selector(HomeScene::menuItemCallBack)); bu02->setTag(2); bu02->setPosition(ccp(165, 0)); CCMenuItemImage *bu03 = CCMenuItemImage::create("fuben.png", "fuben.png", this, menu_selector(HomeScene::menuItemCallBack)); bu03->setTag(3); bu03->setPosition(ccp(270, 0)); CCMenuItemImage *bu04 = CCMenuItemImage::create("huodong.png", "huodong.png", this, menu_selector(HomeScene::menuItemCallBack)); bu04->setTag(4); bu04->setPosition(ccp(375, 0)); CCMenuItemImage *bu05 = CCMenuItemImage::create("beibao.png", "beibao.png", this, menu_selector(HomeScene::menuItemCallBack)); bu05->setTag(5); bu05->setPosition(ccp(480, 0)); CCMenuItemImage *bu06 = CCMenuItemImage::create("shangcheng.png", "shangcheng.png", this, menu_selector(HomeScene::menuItemCallBack)); bu06->setTag(6); bu06->setPosition(ccp(585, 0)); CCMenu* menu = CCMenu::create(bu01, bu02, bu03, bu04, bu05, bu06, NULL); menu->setPosition(ccp(0, 60)); menu->setAnchorPoint(ccp(0, 0.5)); this->addChild(menu); //系统公告 CCLabelTTF* sysLabel = CCLabelTTF::create("系统公告板:展示系统消息", "", 24.0f); sysLabel->setAnchorPoint( ccp(0, 0.5f) ); sysLabel->setPosition( ccp(size.width, size.height-25) ); this->addChild(sysLabel, 0, 100); // CCMoveBy* pMove = CCMoveBy::create(10.0f, ccp(-size.width-sysLabel->getContentSize().width, 0)); CCAction* pStop = CCCallFuncND::create(this, callfuncND_selector(HomeScene::actionDidFinished), NULL); sysLabel->runAction(CCSequence::create(pMove, pStop, NULL)); sysLabel->runAction(pMove); return true; }
void HomeScene::actionDidFinished(cocos2d::CCObject *object, void *param) { CCSize size = CCDirector::sharedDirector()->getWinSize(); CCLabelTTF* sysLabel = (CCLabelTTF *)(this->getChildByTag(100)); sysLabel->setPosition( ccp(size.width, size.height-25) ); CCMoveBy* pMove = CCMoveBy::create(10.0f, ccp(-size.width-sysLabel->getContentSize().width, 0)); CCAction* pStop = CCCallFuncND::create(this, callfuncND_selector(HomeScene::actionDidFinished), NULL); sysLabel->runAction(CCSequence::create(pMove, pStop, NULL)); }
void SGScrollLabel::constructView() { _arrayLabel = CCArray::create(); _arrayLabel->retain(); for(int i=0;i<=_arrayString->count()/this->getFirstRowWordCount();i++) { std::string string; for(int h=i*this->getFirstRowWordCount();h<(i+1)*getFirstRowWordCount();h++) { if(h >= _arrayString->count()) { break; } CCString *str = (CCString*)_arrayString->objectAtIndex(h); string.append(str->getCString()); } CCLabelTTF *label = CCLabelTTF::create(string.c_str(), FONT_BOXINFO, 24); _arrayLabel->addObject(label); } CCPoint bottomCenter = ccp(_viewSize.width/2,0); for(int i=0;i<_arrayLabel->count();i++) { CCLabelTTF *label = (CCLabelTTF*)_arrayLabel->objectAtIndex(i); label->setPosition(ccpAdd(bottomCenter, ccp(0, - label->getContentSize().height))); label->setOpacity(0.0f); label->setHorizontalAlignment(kCCTextAlignmentLeft); this->addChild(label); //动画 CCDelayTime *delayTime = CCDelayTime::create(i*2.0f); CCMoveTo *move2 = CCMoveTo::create(0.5f,ccpAdd(label->getPosition(), ccp(0, _viewSize.height/10))); CCFadeIn *fadeIn = CCFadeIn::create(0.5f); CCFiniteTimeAction *spawn1 = CCSpawn::create(move2,fadeIn,NULL); CCMoveTo *move = CCMoveTo::create(5.0f, ccpAdd(label->getPosition(), ccp(0, _viewSize.height))); CCMoveTo *move3 = CCMoveTo::create(0.5f, ccpAdd(label->getPosition(),ccp(0, _viewSize.height*11/10))); CCFadeOut *fadeOut = CCFadeOut::create(0.5f); CCFiniteTimeAction *spawn2 = CCSpawn::create(move3,fadeOut,NULL); CCFiniteTimeAction *sequence = CCSequence::create(delayTime,spawn1,move,spawn2,NULL); label->runAction(sequence); } CCDelayTime *delay = CCDelayTime::create(_arrayLabel->count()*2+5); CCCallFunc *call = CCCallFunc::create(this, callfunc_selector(SGScrollLabel::callFunction)); CCFiniteTimeAction *sequence2 = CCSequence::create(delay,call,NULL); this->runAction(sequence2); }
void ScoresLayer::DisplayText(char *text, cocos2d::ccColor3B color, cocos2d::CCPoint ccp, int size) { CCLabelTTF* pLabel = CCLabelTTF::create(text, "Arial", size * 2); pLabel->setColor(color); pLabel->setScale(0.5); pLabel->setPosition(ccp(ccp.x + pLabel->getContentSize().width * pLabel->getScaleX() / 2, ccp.y)); int tag = ccp.x + ccp.y * 10000; this->removeChildByTag(tag); this->addChild(pLabel, 10, tag); }
bool RobotLooseLayer::init() { CCSize mapSize = GameParams::getInstanse()->mapSize(); if ( !initWithColor(ccc4(145,145,145,255 * 0.45f)) ) { return false; } CCLabelTTF *label = CCLabelTTF::create(CCLocalizedString("RobotBroken", "NotLocalized"), "Marker Felt", 42); label->setAnchorPoint( CCPointZero ); label->setPosition( CCPointZero ); addChild(label, 20); setContentSize(CCSizeMake(label->getContentSize().width, label->getContentSize().height)); setPosition(ccp(mapSize.width / 2 - getContentSize().width / 2, -getContentSize().height)); return true; }
AnimatedMenuItem* SelectCollection::createCollectionItem( const JoinyCollection* collection, const SpritesLoader& spl) { std::string collection_name = collection->getCollectionName(); ccColor3B label_color = collection->getCollectionColor(); static ccColor3B closeLevel = GameInfo::getInstance()->getCloseColor(); ccColor3B working = closeLevel; if(collection->isOpenCollection()) { working = label_color; } else if (isFreeOpenFullGame() || GameInfo::getVersion() == Version::Premium) { RW::getLevelManager().makeFullGameVersion(); working = label_color; } CCSprite* background = spl->loadSprite("collection_button.png"); background->setColor(working); AnimatedMenuItem* item = AnimatedMenuItem::create( background, this, menu_selector(SelectCollection::onCollectionSelect)); unsigned int l_num = collection->getLevelsNumber(); std::string l_num_str = AD_to_string(l_num); unsigned int l_curr = collection->getCompletedLevelsNumber(); std::string l_curr_str = AD_to_string(l_curr); std::string label_text = collection_name + " "+ l_curr_str + '/' + l_num_str ; CCLabelTTF* label = CCLabelTTF::create(label_text.c_str(), Fonts::getFontName(), 75); label->setTag(123); item->addChild(label); _item_size = background->getContentSize(); float scale = MIN(1, background->getContentSize().width * 0.7 / label->getContentSize().width); _scale = scale; label->setPosition(ccp(background->getContentSize().width*0.5, background->getContentSize().height*0.5)); label->setAnchorPoint(ccp(0.5, 0.5)); label->setScale(scale); label->setColor(working); return item; }