void FairyControlPanel::initHero(FairyHero* selectHero){ controlType = 2; panelBack->removeAllChildrenWithCleanup(true); CCSize size = panelBack->getContentSize(); int ids[4] = {-1, -1, -1, -1}; for(int i = 0; i < (int)selectHero->skillIds.size(); i++){ ids[i] = selectHero->skillIds.at(i); } CCString* SkillDataFile; XMLParser *skillData; CCMenu* menu = CCMenu::create(); if(ids[0] != -1){ SkillDataFile = CCString::createWithFormat("data/skill%d.xml",ids[0]); skillData = XMLParser::parseWithFile(SkillDataFile->getCString()); CCSprite* skill1 = CCSprite::create(skillData->getString("skillIcon")->getCString()); CCMenuItemSprite*skill1Button = CCMenuItemSprite::create(skill1, skill1, this, menu_selector(FairyControlPanel::fairyMenuCallback)); skill1Button->setTag(leftDrection); skill1Button->setPosition(ccp(size.width / 8, size.height / 2 + 30)); menu->addChild(skill1Button); } if(ids[1] != -1){ SkillDataFile = CCString::createWithFormat("data/skill%d.xml",ids[1]); skillData = XMLParser::parseWithFile(SkillDataFile->getCString()); CCSprite* skill1 = CCSprite::create(skillData->getString("skillIcon")->getCString()); CCSprite* skill2 = CCSprite::create(uiLeftNormal); CCMenuItemSprite* skill2Button = CCMenuItemSprite::create(skill2, skill2, this, menu_selector(FairyControlPanel::fairyMenuCallback)); skill2Button->setTag(holdDrection); skill2Button->setPosition(ccp(2 * size.width / 8, size.height / 2+ 30)); menu->addChild(skill2Button); } if(ids[2] != -1){ SkillDataFile = CCString::createWithFormat("data/skill%d.xml",ids[2]); skillData = XMLParser::parseWithFile(SkillDataFile->getCString()); CCSprite* skill1 = CCSprite::create(skillData->getString("skillIcon")->getCString()); CCSprite* skill3 = CCSprite::create(uiLeftNormal); CCMenuItemSprite* skill3Button = CCMenuItemSprite::create(skill3, skill3, this, menu_selector(FairyControlPanel::fairyMenuCallback)); skill3Button->setTag(rightDrection); skill3Button->setPosition(ccp(3 * size.width / 8, size.height / 2 + 30)); menu->addChild(skill3Button); } if(ids[3] != -1){ SkillDataFile = CCString::createWithFormat("data/skill%d.xml",ids[3]); skillData = XMLParser::parseWithFile(SkillDataFile->getCString()); CCSprite* skill4 = CCSprite::create(skillData->getString("skillIcon")->getCString()); CCMenuItemSprite* skill4Button = CCMenuItemSprite::create(skill4, skill4, this, menu_selector(FairyControlPanel::fairyMenuCallback)); skill4Button->setTag(upDrection); skill4Button->setPosition(ccp(4 * size.width / 8, size.height / 2 + 30)); menu->addChild(skill4Button); } panelBack->addChild(menu); menu->setPosition(ccp(0, - 30)); CCString* heroDataFile = CCString::createWithFormat("data/hero%d.xml",selectHero->heroId / 10 * 10); XMLParser *heroData = XMLParser::parseWithFile(heroDataFile->getCString()); CCLabelTTF* heroName = CCLabelTTF::create(heroData->getString("name")->getCString(), "Arial", 50); heroName->setColor(ccc3(0x00, 0x00, 0x00)); heroName->setAnchorPoint(ccp(0,1)); heroName->setPosition(ccp( 5 * size.width / 8, size.height / 2 + 30)); panelBack->addChild(heroName); }
void ActivityView::CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data) { // 背景 CCSprite* cellBg = CCSprite::create("bg_listview_item.png") ; const float cell_width = cellBg->getContentSize().width+15 ; const float cell_height = cellBg->getContentSize().height+10 ; CCListViewCell* cell = CCListViewCell::node() ; cell->setContentSize(CCSizeMake(cell_width, cell_height)) ; cell->setOpacity(0) ; // cell->setSelectionColor(ccc4(255, 0, 0, 255)) ; cell->setSelectionColor(ccc4(103, 102, 204, 255)) ; data->cell = cell ; CCNode* cellNode = CCNode::create() ; cellNode->setContentSize(CCSizeMake(cell_width, cell_height)) ; cellNode->setAnchorPoint(ccp(0, 0)) ; cellNode->setPosition(ccp(0, 0)) ; cell->addChild(cellNode) ; // 背景 cellBg->setAnchorPoint(ccp(0.5, 0.5)) ; cellBg->setPosition(ccp(cell_width*0.5, cell_height*0.5)) ; cellNode->addChild(cellBg) ; // icon CCSprite* iconMsg = CCSprite::create("icon_activity.png") ; iconMsg->setAnchorPoint(ccp(0, 0.5)) ; iconMsg->setPosition(ccp(cell_width-90, cell_height*0.5)) ; cellNode->addChild(iconMsg, 1) ; // 主题 CCLabelTTF* themeLabel = CCLabelTTF::create("蛇年贺新春,免费拿九玩币","font01.ttf", 24.0f,CCSizeMake(cell_width, 50), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter) ; themeLabel->setColor(ccc3(255, 215, 0)) ; themeLabel->setAnchorPoint(ccp(0, 1)) ; themeLabel->setPosition(ccp(20, cell_height-8)) ; cellNode->addChild(themeLabel, 1) ; // 内容 CCLabelTTF* contentLabel = CCLabelTTF::create("蛇年贺新春,免费拿九玩币,蛇年贺新春,免费拿九玩币", "font01.ttf", 20.0f,CCSizeMake(cell_width, 50),kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter) ; contentLabel->setAnchorPoint(ccp(0, 0)) ; contentLabel->setPosition(ccp(20, 8)) ; cellNode->addChild(contentLabel, 1) ; }
void StatusUpgrade::addElements(std::string name, CCPoint position){ CCLabelTTF* strength = CCLabelTTF::create(name.c_str(), "Thonburi", 10); strength->setAnchorPoint(ccp(0,0.5)); strength->setPosition(ccp(30, position.y)); strength->setColor(ccc3(0,0,0)); this->addChild(strength, 1); CCLabelTTF* currentLabel = CCLabelTTF::create(CCString::createWithFormat("%d", this->_current)->getCString(), "arial", 10); currentLabel->setAnchorPoint(ccp(0,0.5)); currentLabel->setPosition(ccp(90, position.y)); currentLabel->setColor(ccc3(0,0,0)); this->addChild(currentLabel); char* desc = this->getDescription(name); CCLabelTTF* description = CCLabelTTF::create(desc, "Thonburi", 8); description->setAnchorPoint(ccp(0,0.5)); description->setPosition(ccp(35, position.y - 20)); description->setColor(ccc3(0,0,0)); this->addChild(description); afterLabel = CCLabelTTF::create(CCString::createWithFormat("-> %d", this->_current + this->_currentAddition)->getCString(), "arial", 10); afterLabel->setAnchorPoint(ccp(0, 0.5)); afterLabel->setPosition(ccp(120, position.y)); afterLabel->setColor(ccc3(0,0,0)); this->addChild(afterLabel); CCSprite* plus = CCSprite::createWithSpriteFrameName("plus.png"); CCSprite* plusOff = CCSprite::createWithSpriteFrameName("plus.png"); plusOff->setColor(ccc3(102,102,102)); CCMenuItemSprite* pPlusButton = CCMenuItemSprite::create(plus, plusOff, this, menu_selector(StatusUpgrade::plus)); CCSprite* minus = CCSprite::createWithSpriteFrameName("minus.png"); CCSprite* minusOff = CCSprite::createWithSpriteFrameName("minus.png"); minusOff->setColor(ccc3(102,102,102)); CCMenuItemSprite* pMinusButton = CCMenuItemSprite::create(minus, minusOff, this, menu_selector(StatusUpgrade::minus)); pPlusButton->setPosition(ccp(position.x - 90, position.y)); pMinusButton->setPosition(ccp(position.x - 50, position.y)); CCMenu* pMenu = CCMenu::create(pPlusButton, pMinusButton, NULL); // pMenu->setTouchPriority(kLevelUpLayerMenuPriority); pMenu->setPosition(CCPointZero); this->addChild(pMenu); }
CCTableViewCell* RankingScene::tableCellAtIndex(CCTableView *table, unsigned int idx) { CCTableViewCell *cell = table->dequeueCell(); cell = new CCTableViewCell(); cell->autorelease(); // Player Point Player * p = (Player*)players->objectAtIndex(idx); CCString *string = CCString::createWithFormat("%d",p->getPoint()); CCLabelTTF *Pointlabel = CCLabelTTF::create(string->getCString(), "Helvetica", 48); Pointlabel->setAnchorPoint(ccp(1, 0)); Pointlabel->setPosition(ccp(500,0)); Pointlabel->setTag(123); cell->addChild(Pointlabel); // Player Name std::string name = p->getName(); CCLabelTTF *Namelabel = CCLabelTTF::create(p->getName().c_str(), "Helvetica", 48); Namelabel->setAnchorPoint(CCPointZero); Namelabel->setPosition(ccp(100, 0)); cell->addChild(Namelabel); // Player Rank char rankBuf[3]; sprintf(rankBuf, "%i.png", idx+1); CCSprite *rank = CCSprite::create(rankBuf); rank->setAnchorPoint(CCPointZero); rank->setPosition(CCPointZero); cell->addChild(rank); if (idx == 0) { int rewardLocal = CCUserDefault::sharedUserDefault()->getIntegerForKey("reward"); std::string nameLocal = GameManager::sharedGameManager()->getName(); int pointMax = CCUserDefault::sharedUserDefault()->getIntegerForKey("pointMax"); if (p->getReward() != 0 && rewardLocal != 0 && p->getName() == nameLocal && p->getPoint() == pointMax) { CCMenuItemImage *bt_send_email = CCMenuItemImage::create("Present.png","Present.png", this, menu_selector(RankingScene::clickBtSendEmail)); CCMenu * menu = CCMenu::create(bt_send_email, NULL); menu->setPosition(ccp(550, 30)); cell->addChild(menu); } } return cell; }
// on "init" you need to initialize your instance bool GameLayer::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } // 2. load texture cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("GameScene.plist"); // init basic data runDistance = 0.0f; coinCount = 0; prevPos = CCPointZero; isGameStart = false; isGameEnd = false; isRunning = false; isSliding = false; isJumpping = false; CCSize winSize = CCDirector::sharedDirector()->getWinSize(); // init map nodes for (int i = 0; i < kGameMapCount; i ++) { CCNode *mapNode = CCNode::create(); this->addChild(mapNode, MapBottomZorder, MapStartTag + i); mapNode->setPosition(ccp(0, winSize.height * i)); this->initMapNode(mapNode); this->resetMapNode(mapNode); } // init map barrier node for (int i = 0; i < kGameMapCount; i ++) { CCNode *barrierNode = CCNode::create(); this->addChild(barrierNode, MapBarrierZorder, MapBarrierStartTag + i); barrierNode->setPosition(ccp(0, winSize.height * i)); this->initBarrierNode(barrierNode); this->resetBarrierNode(barrierNode, MapBarrierStartTag + i); } // init player CCSprite *playerSprite = CCSprite::createWithSpriteFrameName("Role.png"); playerSprite->setPosition(ccp(kGameMapSecondRoad, kPlayerStartAtScreenPosY)); this->addChild(playerSprite, PlayerZorder, PlayerTag); // init score CCLabelTTF *scoreLabel = CCLabelTTF::create("score: 0", "Helvetica", 24); scoreLabel->setAnchorPoint(ccp(0.0f, 0.5f)); scoreLabel->setPosition(ccp(50.0f, winSize.height - 20.0f)); this->addChild(scoreLabel, ScoreLabelZorder, ScoreLabelTag); // touch enabled this->setTouchEnabled(true); return true; }
CCTableViewCell* S11PrepareRes::tableCellAtIndex(CCTableView *table, unsigned int idx) { CCTableViewCell *cell = table->dequeueCell(); if (!cell) { cell = new CustomTableViewCell(); cell->autorelease(); if (idx==0) { selectIndex=0; } CCLabelTTF *label = CCLabelTTF::create("点击输入", "Helvetica", 30.0); label->setColor(ccBLACK); label->setPosition(s11Position8_1_macro(label)); label->setAnchorPoint(CCPointZero); label->setTag(123); cell->addChild(label,101); CCSprite *pSprite = CCSprite::create("s11CellDivideLine.png"); pSprite->setAnchorPoint(CCPointZero); pSprite->setPosition(CCPointZero); cell->addChild(pSprite,101); } else { if (selectIndex ==idx) { if (activeSprite) { activeSprite->removeFromParentAndCleanup(false); } activeSprite = CCSprite::create("s11Active Bar.png"); activeSprite->setAnchorPoint(CCPointZero); activeSprite->setPosition(CCPointZero); cell->addChild(activeSprite,99); } CCLabelTTF *label = (CCLabelTTF*)cell->getChildByTag(123); CCString *aString = CCString::createWithFormat("%u",idx+1); std::string aStr = aString->m_sString; std::map<std::string,std::string>::iterator aIterator = scriptMap.find(aStr); std::string aStr2; if (aIterator !=scriptMap.end()) { aStr2 = aIterator->second; } label->setString(aStr2.c_str()); } return cell; }
void TimeLayer::setUpView() { //label CCLabelTTF *lb = CCLabelTTF::create("Time : 0","arial",24); lb->setAnchorPoint(CCPointZero); lb->setPosition(CCPointZero); this->addChild(lb,0,15); }
bool MainMenu::init() { if ( !CCLayerColor::initWithColor(ccc4(0, 0, 0, 200)) ) { return false; } CCLabelTTF *title = CCLabelTTF::create("Rabbit Run", FONT_NAME, 70); title->setPosition(ccp(SCREEN_CX, SCREEN_HEIGHT - 80)); this->addChild(title); CCMenuItemFont::setFontName(FONT_NAME); CCMenuItemFont::setFontSize(50); char* text[] = {"Score", "Power", "Effect", "+10", "+20%", "--", "+20", "+40%", "grow up", "+10", "+0", "lose weight", "+0", "+0","hiding"}; for(int i = 0; i < 15; i++) { CCLabelTTF *label = CCLabelTTF::create(text[i], FONT_NAME, 50); label->setPosition(ccp(400 + i%3*300, 550 - i/3*85)); this->addChild(label); } char* img[] = {"cabbage.png", "carrot.png", "carrot_ice.png", "carrot_sterlth.png"}; for(int i = 0; i < 4; i++) { CCSprite *sprite = CCSprite::create(img[i]); sprite->setScale(0.2f); sprite->setPosition(ccp(250, 450 - i*80)); this->addChild(sprite); } CCMenuItemFont *startGame = CCMenuItemFont::create("Play", this, menu_selector(MainMenu::startGame)); startGame->setColor(ccc3(0, 255,51)); startGame->setPositionX(-90); CCMenuItemFont *exitGame = CCMenuItemFont::create("Exit", this, menu_selector(MainMenu::exitGame)); exitGame->setColor(ccc3(255, 0, 0)); exitGame->setPositionX(110); CCMenu *menu = CCMenu::create(startGame, exitGame, NULL); menu->setPositionY(120); menu->setTouchPriority(-201); this->addChild(menu); CCLabelTTF *powerBy = CCLabelTTF::create("Power by cocos2d-x", FONT_NAME, 50); powerBy->setAnchorPoint(ccp(1, 0)); powerBy->setPosition(ccp(SCREEN_WIDTH, 0)); this->addChild(powerBy); this->setTouchPriority(-200); this->setTouchMode(kCCTouchesOneByOne); this->setTouchEnabled(true); return true; }
TestController::TestController() : m_tBeginPos(CCPointZero) { CCSize s = CCDirector::sharedDirector()->getWinSize(); CCSprite * pbackground = CCSprite::spriteWithFile("metrobackground.png"); pbackground->setPosition(CCPointMake(s.width/2,s.height/2)); //addChild(pbackground); // add close menu CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(s_pPathClose, s_pPathClose, this, menu_selector(TestController::closeCallback) ); CCMenu* pMenu =CCMenu::menuWithItems(pCloseItem, NULL); pMenu->setPosition( CCPointZero ); pCloseItem->setPosition(CCPointMake( 30, s.height - 50)); // add title COCOS2S-X CCLabelTTF* title = CCLabelTTF::labelWithString("COCOS2D-X-Metro", "Arial", 24); title->setAnchorPoint(CCPointMake(0,0.5)); title->setPosition(CCPointMake(72,s.height - 50)); addChild(title); // Load TestIcons CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile("metroIcons.plist", "metroIcons.png"); char tmp[50]; // add menu items for tests m_pItmeMenu = CCMenu::menuWithItems(NULL); int colorscount = sizeof(ccMetroColors) / sizeof(ccColor4B); for (int i = 0; i < TESTS_COUNT; ++i) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE) CCLabelBMFont* label = CCLabelBMFont::labelWithString(g_aTestNames[i].c_str(), "fonts/arial16.fnt"); #else CCLabelTTF* label = CCLabelTTF::labelWithString(g_aTestNames[i].c_str(), "Arial", 24); #endif // Create Metro MenuItem CCMenuItemMetro* pMenuItem = CCMenuItemMetro::itemWithMetro(label, this, menu_selector(TestController::menuCallback)); pMenuItem->setAnchorPoint(CCPointMake(0,0)); pMenuItem->setMetroSlyte(ccMetroColors[i % colorscount]); m_pItmeMenu->addChild(pMenuItem, i + 10000); pMenuItem->setPosition(CCPointMake(70 + (i / 3) * (MetroRectW + 10),((MetroRectH + 10)* 3) - (i % 3) * (MetroRectH + 10) - 85)); //Icons sprintf(tmp, "metroicon%d.png", i); CCSpriteFrame* frame = cache->spriteFrameByName(tmp); CCSprite* pIcon = CCSprite::spriteWithSpriteFrame(frame); pMenuItem->addChild(pIcon); pIcon->setPosition(CCPointMake(80,60)); } m_pItmeMenu->setContentSize(CCSizeMake((TESTS_COUNT / 3 + 1) * (MetroRectW + 10) - s.width, s.height)); m_pItmeMenu->setPosition(s_tCurPos); addChild(m_pItmeMenu); setIsTouchEnabled(true); addChild(pMenu, 1); }
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; }
bool CustomPop::init(){ if(!CCLayerColor::initWithColor(ccc4(0, 0, 0, 180))){ return false; } this->setTouchEnabled(true); CCSize size=CCDirector::sharedDirector()->getWinSize(); this->setContentSize(size); CCSprite *bkg = CCSprite::create("common_pop_bkg.png"); bkg->setPosition(ccp(size.width/2, size.height/2)); this->addChild(bkg); CCSize sz = bkg->getContentSize(); ccColor3B black1 = ccc3(236, 190, 108); ccColor3B black = ccc3(27, 18, 6); CCLabelTTF* title = CCLabelTTF::create("提 示", "hycc.ttf", 28); title->setColor(black); title->setAnchorPoint(ccp(0.5, 1)); title->setPosition(ccp(sz.width/2+1, sz.height-23)); bkg->addChild(title); CCLabelTTF* title1 = CCLabelTTF::create("提 示", "hycc.ttf", 28); title1->setColor(black1); title1->setAnchorPoint(ccp(0.5, 1)); title1->setPosition(ccp(sz.width/2, sz.height-22)); bkg->addChild(title1); desc = CCLabelTTF::create("", "hycc.ttf", 25,CCSizeMake(400, 0),kCCTextAlignmentCenter); desc->setColor(black); // desc->setAnchorPoint(ccp(0.5, 1)); desc->setPosition(ccp(sz.width/2, sz.height/2+10)); bkg->addChild(desc); CCMenuItemImage* bz = CCMenuItemImage::create("common_btn_ok_1.png", "common_btn_ok_2.png", this, menu_selector(CustomPop::close)); // bz->setAnchorPoint(ccp(0,0)); // bz->setPosition(ccp(sz.width/2, 30)); bz->setScale(1.3); btnsMenu = CCMenu::create(bz,NULL); btnsMenu->setPosition(ccp(sz.width/2,80)); bkg->addChild(btnsMenu); return true; }
bool MainLayer::init() { /*-- 设置整体层属性 --*/ this->setTouchMode(kCCTouchesOneByOne); this->setTouchEnabled(true); this->scheduleUpdate(); CCSize s = CCDirector::sharedDirector()->getWinSize(); this->ignoreAnchorPointForPosition(true); setAnchorPoint(ccp(0.5f, 0.5f)); this->setContentSize(s); setPosition(ccp(s.width / 2, s.height / 2)); CCSize vsize = CCDirector::sharedDirector()->getVisibleSize(); float width = vsize.width / 2; float height = vsize.height / 2; Counter *counter = Counter::sharedCounter(); counter->clearScore(); if (counter->isSound() && !SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying()) { SimpleAudioEngine::sharedEngine()->playBackgroundMusic("bgm.mp3", true); } /*-- door --*/ CCAnimation *doorAnimation = CCAnimationCache::sharedAnimationCache()->animationByName("door"); //左侧 CCSprite *leftDoor = CCSprite::createWithSpriteFrameName("door_1.png"); leftDoor->setPosition(ccp(-200, -50)); leftDoor->setAnchorPoint(ccp(0.5, 0.5)); this->addChild(leftDoor); leftDoor->runAction( CCRepeatForever::create(CCAnimate::create(doorAnimation))); //右侧 CCSprite *rightDoor = CCSprite::createWithSpriteFrameName("door_1.png"); rightDoor->setPosition(ccp(200, -50)); rightDoor->setAnchorPoint(ccp(0.5, 0.5)); this->addChild(rightDoor); rightDoor->runAction( CCRepeatForever::create(CCAnimate::create(doorAnimation))); /*-- 分数 --*/ CCLabelTTF *titletxt = CCLabelTTF::create(counter->getStringByKey("score"), counter->getStringByKey("font"), 46); titletxt->setColor(ccc3(98, 104, 191)); titletxt->setAnchorPoint(ccp(0.5, 0.5)); titletxt->setPosition(ccp(0, height - 130)); this->addChild(titletxt); CCNode *scoreLabel = counter->create_label(); scoreLabel->setPosition(ccp(0, height - 200)); scoreLabel->setAnchorPoint(ccp(0.5, 1)); this->addChild(scoreLabel, 3, TAG_SCORE); /*-- role --*/ return true; }
/** * 初始化方法,继承CCLayer的方法 */ bool WelcomeView::init() { if(!CCLayer::init()) { return false ; } CCSize winSize = CCDirector::sharedDirector()->getWinSize() ; // 背景 CCSprite* downBg = CCSprite::create("bg_welcome.png") ; downBg->setAnchorPoint(ccp(0.5, 0)) ; downBg->setPosition(ccp(winSize.width/2, 0)) ; this->addChild(downBg, 0) ; // 加载logo CCSprite* logo = CCSprite::create("logo_01.png") ; logo->setAnchorPoint(ccp(0.5, 0.5)) ; logo->setPosition(ccp(winSize.width/2, winSize.height/2)) ; this->addChild(logo, 1) ; //////////////////////////// LOADING ////////////////////////////////////////// CCLabelTTF* loadingLabel = CCLabelTTF::create("LOADING...", "Arial", 26) ; loadingLabel->setAnchorPoint(ccp(0.5, 0)) ; loadingLabel->setPosition(ccp(winSize.width/2, 65)) ; loadingLabel->setHorizontalAlignment(kCCTextAlignmentCenter) ; // 水平对齐方式 loadingLabel->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; // 垂直对齐方式 this->addChild(loadingLabel, 1) ; ///////////////////////////////// 进度条 ////////////////////////////////////////// const float margin_bottom = 38.0f ; // 进度条背景 CCSprite* progressBarBg = CCSprite::create("bg_loading.png") ; progressBarBg->setAnchorPoint(ccp(0.5, 0)) ; progressBarBg->setPosition(ccp(winSize.width/2, margin_bottom)); this->addChild(progressBarBg, 1) ; // 进度条 progressBar = CCProgressTimer::create(CCSprite::create("bg_loading_icon.png")); progressBar->setType( kCCProgressTimerTypeBar ); //设置进度条为水平 // Setup for a bar starting from the left since the midpoint is 0 for the x progressBar->setMidpoint(ccp(0,0)); // Setup for a horizontal bar since the bar change rate is 0 for y meaning no vertical change progressBar->setBarChangeRate(ccp(1, 0)); // 设置进度条的长度和高度开始变化的大小 progressBar->setAnchorPoint(ccp(0.5, 0)) ; progressBar->setPosition(ccp(winSize.width/2, margin_bottom+2)); this->addChild(progressBar, 1) ; return true ; }
bool InterfaceRenderer::init() { if( !CCLayer::init() ) return false; CCSize designResolutionSize = CCEGLView::sharedOpenGLView()->getDesignResolutionSize(); CCLabelTTF* label = CCLabelTTF::create("분당우리교회 청년2부 행복나무", "Arial", 100); label->setAnchorPoint(ccp(0.5f, 1)); label->setPosition(ccp(designResolutionSize.width/2, designResolutionSize.height-label->getDimensions().height)); this->addChild(label); // { // editbox = CCEditBox::create(CCSizeMake(800, 100), CCScale9Sprite::create("green_edit.png")); // editbox->retain(); // editbox->setPosition(ccp(designResolutionSize.width/2, 10)); // editbox->setAnchorPoint(ccp(0.5f, 0)); // editbox->setPlaceHolder("테스트용 단어를 입력해주세요."); // editbox->setFont("Arial", 60); // editbox->setFontColor(ccBLACK); // this->addChild(editbox); // } CCMenuItemFont::setFontSize(80); CCMenuItemFont::setFontName("Arial"); // for test button // { // CCMenuItemFont* item = CCMenuItemFont::create("Add", this, menu_selector(InterfaceRenderer::onTouchedDone)); // item->setAnchorPoint(ccp(0, 0)); // item->setPosition(ccp(editbox->getContentSize().width+10, 0)); // // CCMenuItemFont* printItem = CCMenuItemFont::create("Print", this, menu_selector(InterfaceRenderer::onTouchedPrint)); // printItem->setAnchorPoint(ccp(0, 0)); // printItem->setPosition(ccp(editbox->getContentSize().width+10*2+item->boundingBox().size.width, 0)); // // CCMenu* menu = CCMenu::create(item,printItem,NULL); // menu->setPosition(ccp(0, 0)); // menu->setAnchorPoint(ccp(0, 0)); // editbox->addChild(menu); // } // for menually refresh button { CCMenuItemFont* item1 = CCMenuItemFont::create("requestWord", this, menu_selector(InterfaceRenderer::onTouchedRequestWord)); CCMenuItemFont* item2 = CCMenuItemFont::create("requestMistake", this, menu_selector(InterfaceRenderer::onTouchedRequestMistake)); CCMenu* menu = CCMenu::create(item1, item2, NULL); menu->alignItemsVerticallyWithPadding(10); this->addChild(menu); } return true; }
bool CCRoomTableCell::init() { this->_roomInfo = NULL; this->setHasRoom(false); CCLabelTTF *pLabel = CCLabelTTF::create("No Room", f_AmericanTypewriter, FONT_SIZE(kCCRoomTableCellFontSize)); pLabel->setAnchorPoint(CCPointZero); this->addChild(pLabel); this->setLabel(pLabel); return this->init(NULL); }
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; }
void ZhuangbeiXilianUI::clickXilianJingHua(CCObject *obj) { if (m_dInfoDialog) { m_dInfoDialog->removeFromParent(); m_dInfoDialog = NULL; } string tishiStr = LFStrings::getValue("XilianJingHuaShuoMing"); string cailiaoFileStr = "daoju_youlanzhiye.png"; //弹框背景 BaseSprite* dialog = BaseSprite::create("gongjiang_duanzao_cailiaobuzu_tanchukuang.png"); dialog->setPosition(ccp(mWinSize.width/2, mWinSize.height/2 + 50)); //提示 { BaseSprite *cailiaoBg = BaseSprite::create("daoju_kuang_bg.png"); dialog->addChild(cailiaoBg); cailiaoBg->setPosition(ccp(cailiaoBg->getContentSize().width/2 + 10, dialog->getContentSize().height/2)); BaseSprite *cailiaoImg = BaseSprite::create(cailiaoFileStr); cailiaoBg->addChild(cailiaoImg); cailiaoImg->setPosition(ccp(cailiaoBg->getContentSize().width/2, cailiaoBg->getContentSize().height/2)); CCLabelTTF* lable = CCLabelTTF::create(tishiStr.c_str(), fontStr_kaiti,20,CCSize(240, 0), kCCTextAlignmentLeft); dialog->addChild(lable); lable->setAnchorPoint(ccp(0,0.5)); lable->setPosition(ccp(cailiaoBg->getPositionX()+cailiaoBg->getContentSize().width/2 , dialog->getContentSize().height/2)); } //按键 CCMenu* menu = CCMenu::create(); { CCMenuItemImage* item = CCMenuItemImage::create( "gongjiang_duanzao_cailiaobuzu_tanchukuang.png", "gongjiang_duanzao_cailiaobuzu_tanchukuang.png", this, menu_selector(ZhuangbeiXilianUI::clickCiaoliaoShuoMing)); menu->addChild(item); item->setPosition(ccp(dialog->getContentSize().width/2, dialog->getContentSize().height/2)); item->setOpacity(0); item->setScaleX(mWinSize.width / dialog->getContentSize().width); item->setScaleY(mWinSize.height / dialog->getContentSize().height); // item->setScaleX(mWinSize.width / item->getContentSize().width); // item->setScaleY(mWinSize.height / item->getContentSize().height); } //弹框 { LFAlert* lfAlert = new LFAlert(); lfAlert->setBaseContainer(dialog,menu); CCDirector::sharedDirector()->getRunningScene()->addChild(lfAlert,128); lfAlert->release(); m_dInfoDialog = lfAlert; } }
bool GameAbout::init() { if (!CCLayer::init()) { return false; } CCSize size = CCDirector::sharedDirector()->getWinSize(); CCSprite *bg = CCSprite::create("bg.png"); bg->setPosition(ccp(size.width/2, size.height/2)); bg->setScale(0.5f); this->addChild(bg, 0, 0); CCSprite *bgStar = CCSprite::create("moon.png"); bgStar->setAnchorPoint(ccp(0.5, 0)); bgStar->setPosition(ccp(size.width/3, 0)); bgStar->setScale(0.5f); this->addChild(bgStar, 1, 1); CCSprite *frame = CCSprite::create("tb.png"); frame->setPosition(ccp(size.width/2, size.height/2)); frame->setScale(0.5f); this->addChild(frame, 2, 2); char info[256]; sprintf(info, "name: meow war\n\nprogram: aiyiai\n\nart design: wa wa\n\ncompany: xi an men\n\n powered by cocos2d-x"); CCLabelTTF *label = CCLabelTTF::create(info, "Marker Felt", 40, CCSizeMake(400, 400), kCCTextAlignmentLeft); label->setAnchorPoint(ccp(0, 1)); label->setPosition(ccp(50, 600)); label->setColor(ccc3(200, 200, 200)); frame->addChild(label); CCSprite *aboutTitle = CCSprite::create("about.png"); aboutTitle->setPosition(ccp(size.width/2, size.height - 20)); aboutTitle->setScale(0.5f); this->addChild(aboutTitle, 3, 3); CCMenuItemImage *backItem = CCMenuItemImage::create("backA.png", "backB.png", this, menu_selector(GameAbout::menuBackCallback)); backItem->setPosition(ccp(size.width - 20, size.height - 20)); backItem->setScale(0.5f); backItem->setEnabled(false); CCMenu *mainMenu = CCMenu::create(backItem, NULL); mainMenu->setPosition(CCPointZero); this->addChild(mainMenu, 3, 4); return true; }
CCLayer* NewbieQuest1ToBattle::getDescLayer() { CCLayer* layer = CCLayer::create(); CCLabelTTF* descTitle = CCLabelTTF::create("任务简报:","Arial",25); descTitle->setAnchorPoint(ccp(0,0.5)); descTitle->setPosition(ccp(25,360)); descTitle->setColor(ccc3(255,120,0)); CCLabelTTF* desc = CCLabelTTF::create(GXUtil::insertNewline(" 指挥官,据总部消息,德军暗中建设了一个前哨站。艾森豪威尔司令指示,为了登陆作战的最终胜利,不惜一切代价将它摧毁。总部支援部队已到达,指挥这些部队,进攻!",15).c_str(),"Arial",23,CCSizeZero, kCCTextAlignmentLeft, kCCVerticalTextAlignmentTop); desc->setAnchorPoint(ccp(0,1)); desc->setPosition(ccp(25,340)); desc->setColor(ccc3(230, 207, 185)); CCLabelTTF* destTitle = CCLabelTTF::create("任务目标:","Arial",25); destTitle->setAnchorPoint(ccp(0,1)); destTitle->setPosition(ccp(25,150)); destTitle->setColor(ccc3(255,120,0)); CCLabelTTF* dest = CCLabelTTF::create(" [已完成] 视察基地。","Arial",23); dest->setAnchorPoint(ccp(0,1)); dest->setPosition(ccp(25,115)); dest->setColor(ccc3(230, 207, 185)); CCSprite* tixing; tixing = CCSprite::createWithSpriteFrameName("questAppear.png"); tixing->setScale(0.45); tixing->setPosition(ccp(55,101)); tixing->runAction(CCRepeatForever::create(static_cast<CCSequence*>(CCSequence::create(CCScaleTo::create(1, 0.5), CCScaleTo::create(1,0.45),NULL) ))); layer->addChild(descTitle); layer->addChild(desc); layer->addChild(destTitle); layer->addChild(dest); layer->addChild(tixing); return layer; }
void TitleBar::setTitleStringLab(const char* str) { removePreTitle(); CCLabelTTF* titleLabel = CCLabelTTF::labelWithString(str, CCSizeMake(300, 40), CCTextAlignmentLeft, FONTSTHEITISCM, 40); titleLabel->setAnchorPoint(CCPointMake(0.0, 0.5)); titleLabel->setPosition(CCPointMake(60, 45)); addChild(titleLabel); titleLabel->setTag(kTitleBarLabel); }
bool ActorBoardLayer::tabViewInitPage( CCNode* pTabLayer,cocos2d::CCNode *pPage, int nPage) { char str[64] = {0}; sprintf(str, "%d", nPage); CCMenuItem* menuitem = CCMenuItem::create(); CCLabelTTF* text = CCLabelTTF::create( str, "Arial", 22); text->setAnchorPoint(CCPointZero); text->setColor(ccBLACK); menuitem->addChild(text); pPage->addChild(menuitem); return true; }
void GameLayer::setScore(int var) { score = var; if (!mScoreLabel) { CCLabelTTF *label = CCLabelTTF::create(CCString::createWithFormat("%d", getScore())->getCString(), "ArialMT", 30); label->setColor(ccYELLOW); label->setAnchorPoint(ccp(0, .5)); label->setPosition(ccp(50, getContentSize().height * 0.9)); this->addChild(label, ZORDER_COUNTDOWN); mScoreLabel = label; } mScoreLabel->setString(CCString::createWithFormat("Score: %d", getScore())->getCString()); }
CCTableViewCell* S3PracticeScene::tableCellAtIndex(CCTableView *table, unsigned int idx) { // CCString *strCell = CCString::createWithFormat("Practice %d",idx); CCString *strCell = CCString::create(aVectorCellValue[idx].c_str()); CCTableViewCell *pCell = table->dequeueCell(); if (!pCell) { pCell = new CCTableViewCell(); pCell->autorelease(); CCSprite *pSprite = CCSprite::create();//("cellLine.png"); pSprite->setAnchorPoint(CCPointZero); pSprite->setPosition(CCPointZero); pCell->addChild(pSprite); { CCLabelTTF *pLabel = CCLabelTTF::create(strCell->getCString(), "Arial", s3FontSize3_macro, s3Size2_macro(aCell), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter); pLabel->setPosition(ccp(s3Less2_macro,0)); pLabel->setAnchorPoint(CCPointZero); pLabel->setColor(ccc3(0,0,0)); pLabel->setTag(10); pCell->addChild(pLabel,1); } { CCLabelTTF *pLabel = CCLabelTTF::create("Locked", "Arial",s3FontSize3_macro, s3SizeCellLaterLabel_macro, kCCTextAlignmentRight, kCCVerticalTextAlignmentCenter); pLabel->setPosition(s3Position8_macro(aItem)); pLabel->setAnchorPoint(CCPointZero); pLabel->setColor(ccc3(0,0,255)); pLabel->setTag(10); pCell->addChild(pLabel,1); } } CCLabelTTF *pLabel = (CCLabelTTF*)pCell->getChildByTag(10); pLabel->setString(strCell->getCString()); return pCell; }
void GameLayer::beginCountdown(int second) { preCountdown(); setCountdownNum(second); CCSize size = CCDirector::sharedDirector()->getWinSize(); CCLabelTTF *label = CCLabelTTF::create(CCString::createWithFormat("%d", getCountdownNum())->getCString(), "ArialMT", 100); label->setColor(ccRED); label->setAnchorPoint(ccp(.5, .5)); label->setPosition(ccp(size.width * .5, size.height * .5)); this->addChild(label, ZORDER_COUNTDOWN); this->schedule(schedule_selector(GameLayer::countdownSeconds), 0.8); label->setTag(TagCountdown); doCountdownAnimation(label); }
CCLabelTTF* lable(CCNode* toAdd, string lableStr,CCPoint leftPos,float size,string frontStr) { CCLabelTTF *l = CCLabelTTF::create(lableStr.c_str(), frontStr.c_str(), size); //setLablePos(l,leftPos); if(leftPos.x != 0 || leftPos.y != 0) { l->setAnchorPoint(ccp(0, 0.5)); } l->setPosition(leftPos); if (toAdd) { toAdd->addChild(l); } return l; }
bool TestLayer::init() { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); m_pItemMenu = CCMenu::create(); for (int i = 0; i < TESTS_COUNT; ++i) { CCLabelTTF* label = CCLabelTTF::create(g_aTestNames[i].c_str(), "Verdana-Italic", 18); label->setAnchorPoint(ccp(0, 0.5)); CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(TestLayer::menuCallback)); m_pItemMenu->addChild(pMenuItem, i + 1); } m_pItemMenu->alignItemsVerticallyWithPadding(12); m_pItemMenu->setPosition(ccp(winSize.width / 2, winSize.height * 3 / 4)); addChild(m_pItemMenu); return CCLayerColor::initWithColor(ccc4(0, 245, 255, 100), winSize.width, winSize.height); }
CCLabelTTF* addLabelTTF(CCNode *par, const char* value, const char* font, int size, CCPoint pos, CCPoint anchor, ccColor3B color, int zOrder) { CCLabelTTF* target = CCLabelTTF::create(value , font , size ); target->setAnchorPoint(anchor); target->setPosition(pos); target->setColor(color); par->addChild(target, zOrder); return target; }
bool QuestionLayer::init() { if (!CCLayer::init()) { return false; } timerTotal = 12; rightAnswer = 0; errorAnswer = 0; rightLimit = 0; serialNo = 0; CCLOG("queType:%d", queType); if (is_realy_fight == false) { number_in_group = 1; } else { number_in_group = 5; } CCSize size = this->getContentSize(); //开始显示题型 const char* str = NULL; if (queType == SingleQuestion) { str = "单选题"; timerTotal = 15; } else if (queType == JudgeQuestion) { str = "判断题"; timerTotal = 12; } else { str = "多选题"; timerTotal = 30; } CCLabelTTF* ttf = CCLabelTTF::create(str, "STHeitiK-Medium", 36); ttf->setAnchorPoint(ccp(0.5f, 0.5f)); ttf->setPosition(ccp(0, 120)); this->addChild(ttf, 0, 1234); CCScaleTo* scaleTo = CCScaleTo::create(1.0f, 2.0f); CCAction* pAction = CCCallFuncND::create(this, callfuncND_selector(QuestionLayer::start), NULL); ttf->runAction(CCSequence::create(scaleTo, pAction, NULL)); // GameSoundManager::shareManager()->playReadyGoEffect(); isAnswerFinished = false; return true; }
bool MainMenu::initPassAndPlay() { this->removeChildByTag( Child::CCMenuItem_passAndPlay, true ); CCMenuItem* item = CCMenuItem::create( this, menu_selector( MainMenu::passAndPlayCallback ) ); CCSprite* sprite = CCSprite::create( "button_passAndPlay.png" ); sprite->setAnchorPoint(CCPointZero); item->setContentSize( sprite->getContentSize() ); item->addChild( sprite ); CCLabelTTF* label = CCLabelTTF::create("Pass and Play", "American Typewritter.ttf", 24); label->setAnchorPoint(CCPointZero); label->setPosition( ccp( sprite->getContentSize().width * 0.25, sprite->getContentSize().height * 0.5 ) ); item->addChild(label); this->addChild( item, 0, Child::CCMenuItem_passAndPlay ); return true; }
bool GameAbout::init() { if ( !CCLayer::init() ) { return false; } CCSize size = CCDirector::sharedDirector()->getWinSize(); //初始化背景 CCSprite* bg = CCSprite::create("bg.png"); bg->setScale(0.5); bg->setPosition( ccp(size.width/2, size.height/2) ); this->addChild(bg, 0,0); //初始化星球 CCSprite*bgstar = CCSprite::create("moon.png"); bgstar->setAnchorPoint(ccp(0.5,0)); bgstar->setScale(0.5); bgstar->setPosition(ccp(size.width/3 * 1, 0)); this->addChild(bgstar,1,1); //初始化关于框 CCSprite*kuang = CCSprite::create("tb.png"); kuang->setScale(0.5); kuang->setPosition(ccp(size.width/2, size.height/2)); this->addChild(kuang,2,2); char inf[256]; sprintf(inf,"name:meow war\n\nprogram:shuoquan man\n\nart design:peng xu\n\ncompany:hz books\n\n powered by cocos2D-x"); CCLabelTTF * myjineng = CCLabelTTF::create(inf,CCSizeMake(400,400),kCCTextAlignmentLeft, "Marker Felt", 40); myjineng->setAnchorPoint(ccp(0,1)); myjineng->setColor(ccc3(200,200,200)); myjineng->setPosition(ccp(50,600)); kuang->addChild(myjineng); //初始化关于标题 CCSprite*abouttitle = CCSprite::create("about.png"); abouttitle->setScale(0.5); abouttitle->setPosition(ccp(size.width/2, size.height - 20)); this->addChild(abouttitle,3,3); //初始化返回按钮 CCMenuItemImage *back = CCMenuItemImage::create("backA.png", "backB.png",this,menu_selector(GameAbout::menuBackCallback)); back->setScale(0.5); back->setPosition(ccp(size.width - 20,size.height - 20)); back->setEnabled(false); CCMenu* mainmenu = CCMenu::create(back,NULL); mainmenu->setPosition(ccp(0,0)); this->addChild(mainmenu,3,4); return true; }