bool GameOverLayer::init() { do { CC_BREAK_IF(!CCLayer::init()); CCLayerColor* backgroundLayer = CCLayerColor::create( ccc4(255, 255, 255, 128)); addChild(backgroundLayer); CCSize screenSize = CocosUtils::getScreenSize(); CCMenuItemFont* nextLevel = CCMenuItemFont::create("Next", this, menu_selector(GameOverLayer::menuCallback)); nextLevel->setTag(MENU_ITEM_NEXT_LEVEL); nextLevel->setFontName("Consola"); nextLevel->setFontSize(36); CCMenuItemFont* replay = CCMenuItemFont::create("Replay", this, menu_selector(GameOverLayer::menuCallback)); replay->setTag(MENU_ITEM_REPLAY); replay->setFontName("Consola"); replay->setFontSize(36); CCMenu* menu = CCMenu::create(nextLevel, replay, NULL); menu->alignItemsVertically(); menu->setPosition(screenSize.width/2, screenSize.height/2); addChild(menu); return true; } while (false); return false; }
bool Campaign::init() { if ( !SelectSave::init() ) { return false; } stageNum = stageTag0; SelectStage *stages = SelectStage::create(); addChild(stages); stages->setTag(campTag_SelectStage); CCMenuItemFont *start = CCMenuItemFont::create("START",this,menu_selector(Campaign::menuCloseCallback)); CCMenuItemFont *soldiers = CCMenuItemFont::create("SOLDIERS",this,menu_selector(Campaign::menuCloseCallback)); CCMenuItemFont *mainMenu = CCMenuItemFont::create("mainMenu",this,menu_selector(Campaign::menuCloseCallback)); start->setTag(campTag_start); soldiers->setTag(campTag_soldiers); mainMenu->setTag(campTag_mainMenu); CCMenu *menu = CCMenu::create(start,soldiers,mainMenu,NULL); addChild(menu,10); menu->setPosition(CCPointZero); menu->alignItemsVertically(); CCSize size = menu->getContentSize(); CCLOG("%f %f",size.width,size.height); menu->setPosition(ccp(size.width/6, size.height/6)); // menu->setScale(0.5f); return true; }
void MainScene::CreateMenu() { if(_menu == NULL) { CCSize scrSize = CCDirector::sharedDirector()->getWinSize(); _menu = CCMenu::create(); _menu->setPosition(ccp(0,0)); addChild(_menu); CCMenuItemFont* pItem; CCPoint position; // Create the next/back menu items. for(int page = 0; page < MENU_PAGES; page++) { // Create the Back/Forward buttons for the page. // Back arrow if there is a previous page. if(page > 0) { pItem = CCMenuItemFont::create("Back", this, menu_selector(MainScene::MenuCallback)); pItem->setTag(ARROW_LEFT); position = ccp(page*scrSize.width + scrSize.width*0.1,scrSize.height*0.1); pItem->setPosition(position); pItem->setFontSize(35); pItem->setFontName("Arial"); _menu->addChild(pItem); } if(page < (MENU_PAGES-1)) { pItem = CCMenuItemFont::create("Next", this, menu_selector(MainScene::MenuCallback)); pItem->setTag(ARROW_RIGHT); position = ccp(page*scrSize.width + scrSize.width*0.9,scrSize.height*0.1); pItem->setPosition(position); pItem->setFontSize(35); pItem->setFontName("Arial"); _menu->addChild(pItem); } } // Create the actual items for(int idx = 0; idx < MENU_ITEMS_TOTAL; idx++) { char buffer[256]; sprintf(buffer,"Item #%d",idx); pItem = CCMenuItemFont::create(buffer, this, menu_selector(MainScene::MenuCallback)); pItem->setFontSize(35); pItem->setFontName("Arial"); pItem->setTag(idx); position = CalculatePosition(idx); pItem->setPosition(position); _menu->addChild(pItem); } } }
bool HelloWorld::init() { if ( !CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)) ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCSprite* bg = CCSprite::create("bg.png"); bg->setPosition(ccp(visibleSize.width / 2, visibleSize.height / 2)); this->addChild(bg, 0, 0); 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)); CCMenuItemFont* sBtn = CCMenuItemFont::create("", this, menu_selector(HelloWorld::btnCB)); sBtn->setTag(SBTNTAG); sBtn->setAnchorPoint(CCPointZero); sBtn->setPosition(50, 200); sBtn->setColor(ccRED); CCMenuItemFont* rbtn = CCMenuItemFont::create("", this, menu_selector(HelloWorld::btnCB)); rbtn->setTag(RTBTNTAG); rbtn->setAnchorPoint(CCPointZero); rbtn->setPosition(50, 300); rbtn->setColor(ccGREEN); // create menu, it's an autorelease object pMenu = CCMenu::create(pCloseItem, sBtn, rbtn, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); // show filter node this->setAnchorPoint(CCPointZero); fnode = GaussianBlur::screenBlurNodeInstance(); fnode->reset(this); this->addChild(fnode); updateBtn(SBTNTAG); updateBtn(RTBTNTAG); 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; }
/* Action option callback */ void LuaDecisionTree::actionOption(CCString* str) { CCMenuItemFont::setFontName("Arial"); CCMenuItemFont::setFontSize(16); optionsOnScreen += 1; //Add action option to screen CCString *optionStr = CCString::createWithFormat("[%s)", str); CCMenuItemFont *optionItem = CCMenuItemFont::create(str->getCString() , this , menu_selector(LuaDecisionTree::selectOption)); optionItem->setTag(optionsOnScreen); optionItem->setPosition(ccp(10,135 - optionsOnScreen*20)); optionItem->setAnchorPoint(ccp(0,1)); CCMenu *menu = CCMenu::createWithItem(optionItem); menu->setPosition(ccp(0,0)); optionsNode->addChild(menu); }
void MenuScene::onLoadScene() { m_vMenuItems.push_back("Basic Test"); CCSize tContainerSize = CCSize(700, 100 * m_vMenuItems.size()); CCLayer* pScrollViewContainer = CCLayer::create(); pScrollViewContainer->setPosition(CCPointZero); pScrollViewContainer->setContentSize(tContainerSize); m_pScrollView = CCScrollView::create(CCSize(700, 640)); m_pScrollView->setDirection(kCCScrollViewDirectionVertical); m_pScrollView->ignoreAnchorPointForPosition(false); m_pScrollView->setPosition(CCPoint(480, 320)); m_pScrollView->setContainer(pScrollViewContainer); addChild(m_pScrollView); CCArray* pArray = CCArray::create(); float height = tContainerSize.height; unsigned int i = 0; unsigned int end = m_vMenuItems.size(); for(; i < end; ++i ) { CCMenuItemFont* pFont = CCMenuItemFont::create(m_vMenuItems[i].c_str()); pFont->setTarget(this, menu_selector(MenuScene::onClick)); pFont->setFontSizeObj(45.0f); pFont->setPosition(ccp(700 / 2, height - 100 / 2)); pFont->setTag(i + 1); pArray->addObject(pFont); height -= 100; } CCMenu* pMenu = CCMenu::createWithArray(pArray); pMenu->setPosition(ccp(0,0)); pScrollViewContainer->addChild(pMenu); m_pScrollView->setContentOffset(ccp(0, -(tContainerSize.height - 640))); }
cocos2d::CCMenu* BYGameScene::createPauseMenu() { /// creates autorelease object CCMenuItemFont* continueItem = CCMenuItemFont::create("Continue", this, menu_selector(BYGameScene::continueGame)); continueItem->setTag(GUI_PauseMenu_Continue); CCMenuItemFont* reItem = CCMenuItemFont::create("Restart", this, menu_selector(BYGameScene::resetGame)); CCMenuItemFont* quitItem = CCMenuItemFont::create("Quit", this, menu_selector(BYGameScene::quitGame)); CCMenu* menu = CCMenu::create(continueItem, reItem, quitItem, NULL); menu->alignItemsVerticallyWithPadding(5); CCSize s = CCDirector::sharedDirector()->getWinSize(); menu->setPosition(CCPointMake(s.width / 2, s.height / 2)); menu->setTag(GUI_PauseMenu); return menu; }
CCMenu *BoxMenu::getBoxMenu() { CCSize size = CCDirector::sharedDirector()->getWinSize(); Score *scoreInstance = Score::GetInstance(); scoreInstance->makeNameScore(); TEAM_S *pstTeamScore = scoreInstance->teamScore; CCMenuItemFont *ljxTeam = CCMenuItemFont::create(pstTeamScore[0].nameScore, this, menu_selector(BoxMenu::newGame)); CCMenuItemFont *xxxTeam = CCMenuItemFont::create(pstTeamScore[1].nameScore, this, menu_selector(BoxMenu::newGame)); CCMenuItemFont *birdTeam = CCMenuItemFont::create(pstTeamScore[2].nameScore, this, NULL); CCMenuItemFont *oooTeam = CCMenuItemFont::create(pstTeamScore[3].nameScore, this, menu_selector(BoxMenu::newGame)); CCMenuItemFont *threeTeam = CCMenuItemFont::create(pstTeamScore[4].nameScore, this, menu_selector(BoxMenu::newGame)); CCMenuItemFont *pigTeam = CCMenuItemFont::create(pstTeamScore[5].nameScore, this, menu_selector(BoxMenu::newGame)); CCMenuItemFont *fngngTeam = CCMenuItemFont::create(pstTeamScore[6].nameScore, this, menu_selector(BoxMenu::newGame)); /* ljxTeam->setColor(ccBLACK); xxxTeam->setColor(ccBLACK); birdTeam->setColor(ccBLACK); oooTeam->setColor(ccBLACK); threeTeam->setColor(ccBLACK); pigTeam->setColor(ccBLACK); fngngTeam->setColor(ccBLACK); */ ljxTeam->setTag(TeamLJX); xxxTeam->setTag(TeamXXX); birdTeam->setTag(TeamBird); oooTeam->setTag(TeamOOO); threeTeam->setTag(TeamThree); pigTeam->setTag(TeamPig); fngngTeam->setTag(TeamFngng); CCMenu *menu = CCMenu::create(ljxTeam, xxxTeam, birdTeam, oooTeam, threeTeam, pigTeam, fngngTeam, NULL); menu->alignItemsVertically(); return menu; }
//////////////////////////////////////////////////////// // // ParticleMainScene // //////////////////////////////////////////////////////// void ParticleMainScene::initWithSubTest(int asubtest, int particles) { //srandom(0); subtestNumber = asubtest; CCSize s = CCDirector::sharedDirector()->getWinSize(); lastRenderedCount = 0; quantityParticles = particles; CCMenuItemFont::setFontSize(65); CCMenuItemFont *decrease = CCMenuItemFont::create(" - ", this, menu_selector(ParticleMainScene::onDecrease)); decrease->setColor(ccc3(0,200,20)); CCMenuItemFont *increase = CCMenuItemFont::create(" + ", this, menu_selector(ParticleMainScene::onIncrease)); increase->setColor(ccc3(0,200,20)); CCMenu *menu = CCMenu::create(decrease, increase, NULL); menu->alignItemsHorizontally(); menu->setPosition(ccp(s.width/2, s.height/2+15)); addChild(menu, 1); CCLabelTTF *infoLabel = CCLabelTTF::create("0 nodes", "Marker Felt", 30); infoLabel->setColor(ccc3(0,200,20)); infoLabel->setPosition(ccp(s.width/2, s.height - 90)); addChild(infoLabel, 1, kTagInfoLayer); // particles on stage CCLabelAtlas *labelAtlas = CCLabelAtlas::create("0000", "fps_images.png", 12, 32, '.'); addChild(labelAtlas, 0, kTagLabelAtlas); labelAtlas->setPosition(ccp(s.width-66,50)); // Next Prev Test ParticleMenuLayer* pMenu = new ParticleMenuLayer(true, TEST_COUNT, s_nParCurIdx); addChild(pMenu, 1, kTagMenuLayer); pMenu->release(); // Sub Tests CCMenuItemFont::setFontSize(40); CCMenu* pSubMenu = CCMenu::create(); for (int i = 1; i <= 6; ++i) { char str[10] = {0}; sprintf(str, "%d ", i); CCMenuItemFont* itemFont = CCMenuItemFont::create(str, this, menu_selector(ParticleMainScene::testNCallback)); itemFont->setTag(i); pSubMenu->addChild(itemFont, 10); if (i <= 3) { itemFont->setColor(ccc3(200,20,20)); } else { itemFont->setColor(ccc3(0,200,20)); } } pSubMenu->alignItemsHorizontally(); pSubMenu->setPosition(ccp(s.width/2, 80)); addChild(pSubMenu, 2); CCLabelTTF *label = CCLabelTTF::create(title().c_str(), "Arial", 40); addChild(label, 1); label->setPosition(ccp(s.width/2, s.height-32)); label->setColor(ccc3(255,255,40)); updateQuantityLabel(); createParticleSystem(); schedule(schedule_selector(ParticleMainScene::step)); }
BitmapFontMultiLineAlignment::BitmapFontMultiLineAlignment() { this->setTouchEnabled(true); // ask director the the window size CCSize size = CCDirector::sharedDirector()->getWinSize(); // create and initialize a Label this->m_pLabelShouldRetain = CCLabelBMFont::create(LongSentencesExample, "fonts/markerFelt.fnt", size.width/1.5, kCCTextAlignmentCenter); this->m_pLabelShouldRetain->retain(); this->m_pArrowsBarShouldRetain = CCSprite::create("Images/arrowsBar.png"); this->m_pArrowsBarShouldRetain->retain(); this->m_pArrowsShouldRetain = CCSprite::create("Images/arrows.png"); this->m_pArrowsShouldRetain->retain(); CCMenuItemFont::setFontSize(20); CCMenuItemFont *longSentences = CCMenuItemFont::create("Long Flowing Sentences", this, menu_selector(BitmapFontMultiLineAlignment::stringChanged)); CCMenuItemFont *lineBreaks = CCMenuItemFont::create("Short Sentences With Intentional Line Breaks", this, menu_selector(BitmapFontMultiLineAlignment::stringChanged)); CCMenuItemFont *mixed = CCMenuItemFont::create("Long Sentences Mixed With Intentional Line Breaks", this, menu_selector(BitmapFontMultiLineAlignment::stringChanged)); CCMenu *stringMenu = CCMenu::create(longSentences, lineBreaks, mixed, NULL); stringMenu->alignItemsVertically(); longSentences->setColor(ccRED); m_pLastSentenceItem = longSentences; longSentences->setTag(LongSentences); lineBreaks->setTag(LineBreaks); mixed->setTag(Mixed); CCMenuItemFont::setFontSize(30); CCMenuItemFont *left = CCMenuItemFont::create("Left", this, menu_selector(BitmapFontMultiLineAlignment::alignmentChanged)); CCMenuItemFont *center = CCMenuItemFont::create("Center", this, menu_selector(BitmapFontMultiLineAlignment::alignmentChanged)); CCMenuItemFont *right = CCMenuItemFont::create("Right", this, menu_selector(BitmapFontMultiLineAlignment::alignmentChanged)); CCMenu *alignmentMenu = CCMenu::create(left, center, right, NULL); alignmentMenu->alignItemsHorizontallyWithPadding(alignmentItemPadding); center->setColor(ccRED); m_pLastAlignmentItem = center; left->setTag(LeftAlign); center->setTag(CenterAlign); right->setTag(RightAlign); // position the label on the center of the screen this->m_pLabelShouldRetain->setPosition(ccp(size.width/2, size.height/2)); this->m_pArrowsBarShouldRetain->setVisible(false); float arrowsWidth = (ArrowsMax - ArrowsMin) * size.width; this->m_pArrowsBarShouldRetain->setScaleX(arrowsWidth / this->m_pArrowsBarShouldRetain->getContentSize().width); this->m_pArrowsBarShouldRetain->setPosition(ccp(((ArrowsMax + ArrowsMin) / 2) * size.width, this->m_pLabelShouldRetain->getPosition().y)); this->snapArrowsToEdge(); stringMenu->setPosition(ccp(size.width/2, size.height - menuItemPaddingCenter)); alignmentMenu->setPosition(ccp(size.width/2, menuItemPaddingCenter+15)); this->addChild(this->m_pLabelShouldRetain); this->addChild(this->m_pArrowsBarShouldRetain); this->addChild(this->m_pArrowsShouldRetain); this->addChild(stringMenu); this->addChild(alignmentMenu); }
//////////////////////////////////////////////////////// // // SpriteMainScene // //////////////////////////////////////////////////////// void SpriteMainScene::initWithSubTest(int asubtest, int nNodes) { //srandom(0); subtestNumber = asubtest; m_pSubTest = new SubTest; m_pSubTest->initWithSubTest(asubtest, this); CCSize s = CCDirector::sharedDirector()->getWinSize(); lastRenderedCount = 0; quantityNodes = 0; CCMenuItemFont::setFontSize(65); CCMenuItemFont *decrease = CCMenuItemFont::create(" - ", this, menu_selector(SpriteMainScene::onDecrease)); decrease->setColor(ccc3(0,200,20)); CCMenuItemFont *increase = CCMenuItemFont::create(" + ", this, menu_selector(SpriteMainScene::onIncrease)); increase->setColor(ccc3(0,200,20)); CCMenu *menu = CCMenu::create(decrease, increase, NULL); menu->alignItemsHorizontally(); menu->setPosition(ccp(s.width/2, s.height-65)); addChild(menu, 1); CCLabelTTF *infoLabel = CCLabelTTF::create("0 nodes", "Marker Felt", 30); infoLabel->setColor(ccc3(0,200,20)); infoLabel->setPosition(ccp(s.width/2, s.height-90)); addChild(infoLabel, 1, kTagInfoLayer); // add menu SpriteMenuLayer* pMenu = new SpriteMenuLayer(true, TEST_COUNT, s_nSpriteCurCase); addChild(pMenu, 1, kTagMenuLayer); pMenu->release(); // Sub Tests CCMenuItemFont::setFontSize(32); CCMenu* pSubMenu = CCMenu::create(); for (int i = 1; i <= 9; ++i) { char str[10] = {0}; sprintf(str, "%d ", i); CCMenuItemFont* itemFont = CCMenuItemFont::create(str, this, menu_selector(SpriteMainScene::testNCallback)); itemFont->setTag(i); pSubMenu->addChild(itemFont, 10); if( i<= 3) itemFont->setColor(ccc3(200,20,20)); else if(i <= 6) itemFont->setColor(ccc3(0,200,20)); else itemFont->setColor(ccc3(0,20,200)); } pSubMenu->alignItemsHorizontally(); pSubMenu->setPosition(ccp(s.width/2, 80)); addChild(pSubMenu, 2); // add title label CCLabelTTF *label = CCLabelTTF::create(title().c_str(), "Arial", 40); addChild(label, 1); label->setPosition(ccp(s.width/2, s.height-32)); label->setColor(ccc3(255,255,40)); while(quantityNodes < nNodes) onIncrease(this); }