void BYGameScene::loadUI() { CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); frameCache->addSpriteFramesWithFile("ui.plist", "ui.png"); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); /// pause button CCSprite* btnNormalSprite = CCSprite::createWithSpriteFrameName("pause.png"); CCMenuItemSprite *pauseMenuItem = CCMenuItemSprite::create(btnNormalSprite, btnNormalSprite, this, menu_selector(BYGameScene::pauseButtonHandler)); /// 2 labels for goals ccColor3B color = ccc3(220, 70, 20); /// red color _labelBotPlayerGoalsScored = CCLabelTTF::create("0", "Marker Felt", 40); _labelBotPlayerGoalsScored->setColor(color); CCMenuItemLabel *labelBot = CCMenuItemLabel::create(_labelBotPlayerGoalsScored, NULL, NULL); labelBot->setEnabled(false); _labelTopPlayerGoalsScored = CCLabelTTF::create("0", "Marker Felt", 40); _labelTopPlayerGoalsScored->setColor(color); CCMenuItemLabel *labelTop = CCMenuItemLabel::create(_labelTopPlayerGoalsScored, NULL, NULL); labelTop->setEnabled(false); /// CCMenu doesnt support anchorPoint as of 0x00020003 version CCMenu *menu = CCMenu::create(labelTop, pauseMenuItem, labelBot, NULL); menu->alignItemsHorizontallyWithPadding(5); menu->setAnchorPoint(CCPointMake(0, 0)); menu->setPosition(CCPointMake(winSize.width - pauseMenuItem->getContentSize().width / 2, winSize.height / 2)); menu->setRotation(90); this->addChild(menu); }
void GameScene::showRetryButtons() { CCMenuItemImage* retryButton = CCMenuItemImage::create( "ButtonRetry.png","ButtonRetry.png", this, menu_selector(GameScene::tapRetryButton)); CCMenuItemImage* wallButton = CCMenuItemImage::create( "ButtonWall.png", "ButtonWall.png" , this, menu_selector(GameScene::tapWallButton)); CCMenuItemImage* titleButton = CCMenuItemImage::create( "ButtonTitle.png","ButtonTitle.png", this, menu_selector(GameScene::tapTitleButton)); CCMenu* menu = CCMenu::create(retryButton, wallButton, titleButton, NULL); menu->alignItemsHorizontallyWithPadding( 30.0f); menu->setOpacity(0); //menu->setPosition(ccp(m_winSize.width / 2,m_winSize.height * 1.2)); //menu->setPosition(ccp(m_winSize.width / 2,m_winSize.height/ 4 - 10)); this->addChild(menu,kZOrderScore,kTagMenu); CCFiniteTimeAction* initFade = CCFadeTo::create(0.0f,0); CCFiniteTimeAction* initMove = CCMoveTo::create(0.0f,ccp(m_winSize.width / 2,50.0f - 10.0f)); CCSequence* initMix = CCSequence::createWithTwoActions(initFade,initMove); CCFiniteTimeAction* fade = CCFadeIn::create(1.5f); CCFiniteTimeAction* move = CCMoveBy::create(1.5f,ccp(0,10.0f)); CCSpawn* mix = CCSpawn::createWithTwoActions(fade,move); CCActionInterval* easeMix = CCEaseIn::create( CCSequence::createWithTwoActions(initMix,mix), 2.0f); menu->runAction(easeMix); }
bool GameUI::initWithController(GameScene* controller, int chapter, int level) { { CCMenu* gameplay = CCMenu::node(); { CCSprite* up = CCSprite::spriteWithSpriteFrameName("reset_button.png"); CCSprite* down = CCSprite::spriteWithSpriteFrameName("reset_button_pressed.png"); CCMenuItemSprite* restartButton = CCMenuItemSprite::itemFromNormalSprite(up, down, controller, menu_selector(GameScene::restartGame)); gameplay->addChild(restartButton, 0); } { CCSprite* up = CCSprite::spriteWithSpriteFrameName("pause_button.png"); CCSprite* down = CCSprite::spriteWithSpriteFrameName("pause_button_pressed.png"); CCMenuItemSprite* pauseButton = CCMenuItemSprite::itemFromNormalSprite(up, down, controller, menu_selector(GameScene::pauseGame)); gameplay->addChild(pauseButton, 0); } { BoostBar* boostBar = BoostBar::node(); CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); boostBar->setPosition(ccp(110, screenSize.height - 20)); this->addChild(boostBar, boostBar->getZOrder(), TAG_BOOST); } { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); String levelString = String::withFormat("%d - %d", chapter + 1, level + 1); CCLabelBNFont* levelLabel = CCLabelBNFont::labelWithString(levelString.c_str(), "soupofjustice_24_white.fnt"); levelLabel->setPosition(ccp(screenSize.width - 30, -10)); addChild(levelLabel); CCDelayTime* delayIn = CCDelayTime::actionWithDuration(2); CCMoveBy* moveUp = CCMoveBy::actionWithDuration(0.4, ccp(0, 25)); CCEaseBackOut* moveUpEase = CCEaseBackOut::actionWithAction(moveUp); CCFiniteTimeAction* sequence = CCSequence::actions(delayIn, moveUpEase, 0); levelLabel->runAction(sequence); } { CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); gameplay->setPosition(ccp(screenSize.width - 50, screenSize.height - 20)); gameplay->alignItemsHorizontallyWithPadding(-10); this->addChild(gameplay); } } return true; }
void HelloWorld::createMenu() { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCLabelTTF *editorLabel = CCLabelTTF::create("Editor", "Marker Felt", 24); CCMenuItem *toEditorItem = CCMenuItemLabel::create(editorLabel, this, menu_selector(HelloWorld::switchToEditor)); CCLabelTTF *menuLabel = CCLabelTTF::create("Menu", "Marker Felt", 24); CCMenuItem *toMenuItem = CCMenuItemLabel::create(menuLabel, this, menu_selector(HelloWorld::switchToMenu)); CCMenu *menu = CCMenu::create(toMenuItem,toEditorItem,NULL); menu->setPosition(ccp(winSize.width/2, toEditorItem->getContentSize().height/2)); this->addChild(menu,100); menu->alignItemsHorizontallyWithPadding(winSize.width * 0.1); }
KDvoid LevelEditor::createMenu ( KDvoid ) { const CCSize& tLyrSize = this->getContentSize ( ); CCLabelTTF* pSaveLabel = CCLabelTTF::create ( "Save", "font/Marker Felt.ttf", 24 ); CCMenuItem* pSaveItem = CCMenuItemLabel::create ( pSaveLabel, this, menu_selector ( LevelEditor::saveLevel ) ); CCLabelTTF* pResetLabel = CCLabelTTF::create ( "Select Level", "font/Marker Felt.ttf", 24 ); CCMenuItemLabel* pResetItem = CCMenuItemLabel::create ( pResetLabel, this, menu_selector ( LevelEditor::resetLevel ) ); CCLabelTTF* pPlayLabel = CCLabelTTF::create("Play Level", "font/Marker Felt.ttf", 24); CCMenuItemLabel* pPlayLevelItem = CCMenuItemLabel::create ( pPlayLabel, this, menu_selector ( LevelEditor::playLevel ) ); CCMenu* pMenu = CCMenu::create ( pSaveItem, pResetItem, pPlayLevelItem, KD_NULL ); pMenu->setPosition ( tLyrSize.cx / 2, pSaveItem->getContentSize ( ).cy / 2 ); this->addChild ( pMenu, 100 ); pMenu->alignItemsHorizontallyWithPadding ( 20 ); }
bool MapSelector::init() { if (!CCLayer::init()) { return false; } CCMenuItemImage* leftArrow = CCMenuItemImage::create("left_arrow.png", "left_arrow_selected.png", this, menu_selector(MapSelector::leftButtonPressed)); CCMenuItemImage* rightArrow = CCMenuItemImage::create("right_arrow.png", "right_arrow_selected.png", this, menu_selector(MapSelector::rightButtonPressed)); CCMenu* menu = CCMenu::create(leftArrow, rightArrow, NULL); menu->alignItemsHorizontallyWithPadding(180); this->addChild(menu); _nextMaps = NULL; return true; }
// Add button menu to fail layer. void GameEndLayer::addFailMenu() { CCMenuItemImage* replay = CCMenuItemImage::create(nameOfRestartNormal, nameOfRestartSelect, this, menu_selector(GameEndLayer::onReplay)); replay->setScale(1.5f); CCMenuItemImage* levels = CCMenuItemImage::create(nameOfSelectLevelNormal, nameOfSelectLevelSelect, this, menu_selector(GameEndLayer::onLevels)); levels->setScale(1.5f); CCMenu* menu = CCMenu::create(replay, levels, NULL); //menu->setScale(1.5f); // Padding the items. menu->alignItemsHorizontallyWithPadding(20); menu->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width / 2 , CCDirector::sharedDirector()->getWinSize().height / 3)); this->addChild(menu, 2); }
bool PauseLayer:: init(GameLayer *gameLayer) { if (!CCLayer::init()) { return false; } float scale = Utility::isIPad() ? 1 : 0.5; gLayer = gameLayer; charMenuIemList = new CCArray; // Utility::addSpriteSheet("buttonTexture"); isCallFromRecords = true; winSize = CCDirector::sharedDirector()->getWinSize(); CCLayerColor *colorLayer = CCLayerColor::create(ccc4(50, 50, 50, 100), winSize.width , winSize.height ); addChild(colorLayer); if (gameLayer->sceneType == kSceneTypeGameScene) { addMenuItems("btnNewGame.png", 1); } addMenuItems("btnMenu.png", 2); CCMenu *btnMenu = CCMenu::createWithArray(charMenuIemList); btnMenu->alignItemsHorizontallyWithPadding(winSize.width * 0.05); btnMenu->setPosition(ccp(winSize.width * 0.2, winSize.height * 0.1)); addChild(btnMenu, 2); CCSprite *iconStar = CCSprite::createWithSpriteFrameName("coinsStars_4.png"); iconStar->setScale(0.8); iconStar->setPosition(ccp(winSize.width * 0.05, winSize.height * 0.92)); addChild(iconStar, 2); const char *totalStars = CCString::createWithFormat("%d", Utility::getTotalStars())->getCString(); CCLabelBMFont *starsLabel = CCLabelBMFont::create(totalStars, kFontChubby, 0); starsLabel->setPosition(ccp(iconStar->getPositionX() + winSize.width * 0.05, winSize.height * 0.92)); starsLabel->setScale(scale); addChild(starsLabel, 2); addObjectiveLayer(); hideHUDButtons(); //add resume button createButton("btnResume.png", 3, ccp(winSize.width * 0.9, winSize.height * 0.1)); // createButton("btnSound.png", 4, ccp(winSize.width * 0.95,winSize.height * 0.92)); return true; }
bool HelpScene::init(){ if(BaseScene::init()){ frameCache->addSpriteFramesWithFile("Themes/scene/help_1-hd.plist"); frameCache->addSpriteFramesWithFile("Themes/scene/help_2-hd.plist"); frameCache->addSpriteFramesWithFile("Themes/scene/help_3-hd.plist"); //背景图片 CCSprite* helpBg = SPRITE(help_bg.png); helpBg->setPosition(VisibleRect::center()); addChild(helpBg); //菜单 Home CCMenuItemSprite* homeBtn = CCMenuItemSprite::create(SPRITE(help_home_normal.png), SPRITE(help_home_pressed.png),SceneManager::shareSceneManager(),menu_selector(SceneManager::toHomeSceneFromHelp)); CCMenu* homeMenu = CCMenu::create(homeBtn,NULL); homeMenu->setPosition(ccp(VisibleRect::leftTop().x+70,VisibleRect::leftTop().y-60)); addChild(homeMenu); //切换菜单 helpBtn = CCMenuItemSprite::create(SPRITE(tips_normal_CN.png),SPRITE(tips_normal_CN.png), SPRITE(tips_selected_CN.png),this,menu_selector(HelpScene::tabMenuHandler)); monsterBtn = CCMenuItemSprite::create(SPRITE(monster_normal_CN.png),SPRITE(monster_normal_CN.png), SPRITE(monster_selected_CN.png),this,menu_selector(HelpScene::tabMenuHandler)); towerBtn = CCMenuItemSprite::create(SPRITE(tower_normal_CN.png),SPRITE(tower_normal_CN.png), SPRITE(tower_selected_CN.png),this,menu_selector(HelpScene::tabMenuHandler)); CCMenu* tabMenu = CCMenu::create(helpBtn,monsterBtn,towerBtn,NULL); helpBtn->setEnabled(false); tabMenu->alignItemsHorizontallyWithPadding(0); tabMenu->setPosition(ccp(VisibleRect::top().x,VisibleRect::top().y-50)); addChild(tabMenu); CCLayer* tipLayer = CCLayer::create(); CCLayer* monsterLayer = CCLayer::create(); CCLayer* towerLayer = CCLayer::create(); helpLayers = CCLayerMultiplex::create(tipLayer,monsterLayer,towerLayer,NULL); addChild(helpLayers); setTipLayer(tipLayer); setMonsterLayer(monsterLayer); setTowerLayer(towerLayer); return true; } return false; }
bool SP_Main::createMenu() { bool bRet = false; do { s = CCDirector::sharedDirector()->getWinSize(); // 뒤로가기 버튼 CCMenuItemImage* pBackItem = CCMenuItemImage::create("common/back_btn_2.png", "common/back_pressed_btn_2.png", this, menu_selector(SP_Main::menuClickCallback)); pBackItem->setTag(1); // 다시하기 버튼 CCMenuItemImage* pRetryItem = CCMenuItemImage::create("common/again_btn_2.png", "common/again_pressed_btn_2.png", this, menu_selector(SP_Main::menuClickCallback)); pRetryItem->setTag(2); CCMenu* pMenu = CCMenu::create(); pMenu->addChild(pBackItem); pMenu->addChild(pRetryItem); pMenu->setPosition(ccp(19 + pBackItem->getContentSize().width , s.height - 40)); pMenu->alignItemsHorizontally(); this->addChild(pMenu, 100); // 숫자, 알파벳 보기 m_pShowNItem = CCMenuItemImage::create("common/game/sliding/number_btn.png", "common/game/sliding/number_btn_pressed.png", this, menu_selector(SP_Main::menuShow)); m_pShowAItem = CCMenuItemImage::create("common/game/sliding/alphabet_btn.png", "common/game/sliding/alphabet_btn_pressed.png", this, menu_selector(SP_Main::menuShow)); m_pShowNItem->setTag(0); m_pShowAItem->setTag(1); CCMenu* pMenuShow = CCMenu::create(); pMenuShow->addChild(m_pShowNItem); pMenuShow->addChild(m_pShowAItem); pMenuShow->alignItemsHorizontallyWithPadding(5); pMenuShow->setPosition(SHOWMENU_XY); this->addChild(pMenuShow, 1); bRet = true; } while(0); return bRet; }
bool TitleLayer::init() { if ( !CCLayer::init() ) { return false; } // Get window size CCSize windowSize = CCDirector::sharedDirector()->getWinSize(); // Create text label for title of game - "@stroids" - don't sue me Atari! CCLabelTTF *title = CCLabelTTF::labelWithString("@stroids", "Courier", 64.0); // Position title at center of screen title->setPosition(ccp(windowSize.width / 2, windowSize.height/2)); // Add to layer this->addChild(title, 1); // Set the default CCMenuItemFont font CCMenuItemFont::setFontName("Courier"); // Create "play," "scores," and "controls" buttons - when tapped, they call methods we define: playButtonAction and scoresButtonAction CCMenuItemFont *playButton = CCMenuItemFont::itemFromString("play", this, menu_selector(TitleLayer::playButtonAction)); CCMenuItemFont *scoresButton = CCMenuItemFont::itemFromString("scores", this, menu_selector(TitleLayer::scoresButtonAction)); CCMenuItemFont *controlsButton = CCMenuItemFont::itemFromString("controls", this, menu_selector(TitleLayer::controlsButtonAction)); // Create menu that contains our buttons CCMenu *menu = CCMenu::menuWithItems(playButton, scoresButton, controlsButton, NULL); // Align buttons horizontally menu->alignItemsHorizontallyWithPadding(20); // Set position of menu to be below the title text menu->setPosition(ccp(windowSize.width / 2, title->getPosition().y - title->getContentSize().height / 1.5)); // Add menu to layer this->addChild(menu, 2); return true; }
bool GRPopLayer::init() { bool bRet = false; do { CC_BREAK_IF(!CCLayer::init()); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); //设置这个层的背景图片,并且设置其位置为整个屏幕的中点 CCSprite * background = CCSprite::create("input.png"); m_bgSprite = background; background->setPosition(ccp(winSize.width/2,winSize.height/2)); this->addChild(background); //获得背景图片的大小 CCSize contentSize = background->getContentSize(); m_size = contentSize; //添加俩个菜单在这个层中 CCMenuItemImage * item1 = CCMenuItemImage::create("button.png","button_pressed.png","",this,menu_selector(GRPopLayer::yesButton)); CCMenu * menu = CCMenu::create(item1,NULL,NULL); menu->alignItemsHorizontallyWithPadding(5); menu->setPosition(ccp(contentSize.width/2,contentSize.height/4)); background->addChild(menu); //设置题目和文本内容 this->setContent(); this->setTouchEnabled(true); bRet = true; } while(0); return bRet; }
void MenuLayer2::alignMenusH() { for(int i=0;i<2;i++) { CCMenu *menu = (CCMenu*)getChildByTag(100+i); menu->setPosition( m_centeredMenu ); if(i==0) { // TIP: if no padding, padding = 5 menu->alignItemsHorizontally(); CGPoint p = menu->getPosition(); menu->setPosition( ccpAdd(p, CGPointMake(0,30)) ); } else { // TIP: but padding is configurable menu->alignItemsHorizontallyWithPadding(40); CGPoint p = menu->getPosition(); menu->setPosition( ccpSub(p, CGPointMake(0,30)) ); } } }
bool ControlLayer::init() { if(!CCLayer::init()) { return false; } //创建方向按钮 CCMenuItem *up = CCMenuItemFont::itemWithString("up", this, menu_selector(ControlLayer::menuCallBackMove)); CCMenuItem *down = CCMenuItemFont::itemWithString("down", this, menu_selector(ControlLayer::menuCallBackMove)); CCMenuItem *left = CCMenuItemFont::itemWithString("left", this, menu_selector(ControlLayer::menuCallBackMove)); CCMenuItem *right = CCMenuItemFont::itemWithString("right", this, menu_selector(ControlLayer::menuCallBackMove)); up->setTag(kUp); down->setTag(kDown); left->setTag(kLeft); right->setTag(kRight); CCMenu *menu = CCMenu::menuWithItems(up, down, left, right, NULL); //排列按钮 menu->alignItemsHorizontallyWithPadding(50); this->addChild(menu); return true; }
bool ResultScene::init() { bool result = GradientLayer::init(); if (result) { setTitle(MessageResultTitle); CCSize windowSize = CCDirector::sharedDirector()->getWinSize(); GameEngine *engine = GameEngine::sharedEngine(); CCSprite *braveImage = CCSprite::createWithSpriteFrameName("brave.png"); braveImage->setRotation(90); braveImage->setPosition(ccp(windowSize.width / 2, windowSize.height - kBraveImageMarginTop - braveImage->getContentSize().height / 2)); this->addChild(braveImage); CCLabelTTF *messageLabel = CCLabelTTF::create(engine->getResultMessage(), DefaultFontName, FontSizeSmall); messageLabel->setPosition(ccp(windowSize.width / 2 + kBraveMessageAdjustX, windowSize.height - kBraveMessageMarginTop)); messageLabel->setAnchorPoint(ccp(0.0, 0.0)); this->addChild(messageLabel); float boxBottom = kCommandAreaHeight + kCommandAreaMarginTop + kCommandAreaMarginBottom; CCDrawNode *boxNode = CCDrawNode::create(); CCPoint contentBox[] = {ccp(kBoxMarginHorizontal, windowSize.height - kBoxMarginTop), ccp(windowSize.width - kBoxMarginHorizontal, windowSize.height - kBoxMarginTop), ccp(windowSize.width - kBoxMarginHorizontal, boxBottom), ccp(kBoxMarginHorizontal, boxBottom)}; boxNode->drawPolygon(contentBox, 4, kBoxFillColor, 1, kBoxBorderColor); this->addChild(boxNode); CCString *scoreText = CCString::createWithFormat("%s:%d", MessageScoreText, engine->getScore()); CCLabelTTF *scoreLabel = CCLabelTTF::create(scoreText->getCString(), DefaultFontName, FontSizeNormal); scoreLabel->setPosition(ccp(windowSize.width / 2, windowSize.height - kScoreLabelMarginTop)); this->addChild(scoreLabel); map<hiberlite::sqlid_t, int> *foundItems = engine->getFoundItems(); map<hiberlite::sqlid_t, int>::iterator foundItemsIterator = foundItems->begin(); vector<Item> *items = engine->getItems(); float itemImageAreaMarginLeft = windowSize.width / 2 - ((kNumberOfLineItems / 2 - 1) * (kItemImageSize + kItemImageMarginHorizontal)) - kItemImageMarginHorizontal / 2 - kItemImageSize / 2; int sumFoundItems = 0; int index = 0; while (foundItemsIterator != foundItems->end()) { hiberlite::sqlid_t itemID = (*foundItemsIterator).first; Item item = items->at(itemID - 1); int count = (*foundItemsIterator).second; const char *imageFileName = item->image.c_str(); int posX = index % kNumberOfLineItems; int posY = index / kNumberOfLineItems; CCPoint imagePosition = ccp(itemImageAreaMarginLeft + (kItemImageSize + kItemImageMarginHorizontal) * posX, windowSize.height - kItemImageAreaMarginTop - (kItemImageSize + kItemImageMarginVertical) * posY); CCSprite *itemImage = CCSprite::createWithSpriteFrameName(imageFileName); itemImage->setPosition(imagePosition); this->addChild(itemImage); sumFoundItems += count; if (count > kItemCountMax) { count = kItemCountMax; } CCString *countText = CCString::createWithFormat("%d", count); CCLabelTTF *countLabel = CCLabelTTF::create(countText->getCString(), DefaultFontName, FontSizeSmall); countLabel->setPosition(ccpAdd(imagePosition, ccp(0, -kItemImageSize / 2 - kItemImageCountLabelAdjustY))); this->addChild(countLabel); foundItemsIterator++; index++; } CCString *itemCountText = CCString::createWithFormat("%s:%d", MessageNumberOfFoundItemsText, sumFoundItems); CCLabelTTF *itemCountLabel = CCLabelTTF::create(itemCountText->getCString(), DefaultFontName, FontSizeNormal); itemCountLabel->setPosition(ccp(windowSize.width / 2, windowSize.height - kItemCountLabelMarginTop)); this->addChild(itemCountLabel); CCLayerColor *retryLayer = CCLayerColor::create((ccColor4B){0x00, 0x00, 0x00, 0x00}, kCommandButtonWidth, kCommandButtonHeight); CCLabelTTF *retryLabel = CCLabelTTF::create(MessageRetryButtonTitle, DefaultFontName, FontSizeNormal); retryLabel->setPosition(ccp(kCommandButtonWidth / 2, kCommandButtonHeight / 2)); retryLayer->addChild(retryLabel); CCMenuItem *retryItem = CCMenuItemLabel::create(retryLayer, GameEngine::sharedEngine(), menu_selector(GameEngine::startNewGame)); CCLayerColor *backTitleLayer = CCLayerColor::create((ccColor4B){0x00, 0x00, 0x00, 0x00}, kCommandButtonWidth, kCommandButtonHeight); CCLabelTTF *backTitleLabel = CCLabelTTF::create(MessageBackTitleButtonTitle, DefaultFontName, FontSizeNormal); backTitleLabel->setPosition(ccp(kCommandButtonWidth / 2, kCommandButtonHeight / 2)); backTitleLayer->addChild(backTitleLabel); CCMenuItem *backTitleItem = CCMenuItemLabel::create(backTitleLayer, GameEngine::sharedEngine(), menu_selector(GameEngine::showTitle)); CCMenu *menu = CCMenu::create(retryItem, backTitleItem, NULL); menu->alignItemsHorizontallyWithPadding(kCommandButtonPadding); menu->setPosition(ccp(windowSize.width / 2, kCommandAreaMarginBottom + kCommandAreaHeight / 2)); this->addChild(menu); } return result; }
bool VVAlertView::initWithTitle(const char* aTitle, const char* aMessage, VVAlertViewDelegate* aDelegate, const char* aCancelBtnTitle, const char* aOtherBtnTitle) { if ( !VVPopupLayer::init() ) return false; delegate = aDelegate; overlayLayer->removeFromParentAndCleanup(true); CCLabelTTF *titleLabel = NULL; if( aTitle != NULL ) { titleLabel = CCLabelTTF ::labelWithString(aTitle ,fontName.c_str(), titleFontSize); } CCScale9Sprite *bg = CCScale9Sprite::scale9SpriteWithFile(alertBG_name.c_str(), alert9patch_rect); CCLabelTTF *msgLabel = CCLabelTTF::labelWithString(aMessage, CCSizeMake(maxWidth-borderPadding*4, 0), CCTextAlignmentCenter, fontName.c_str(), messageFontSize); CCMenuItemSprite* btnCancel = CCMenuItemDynamic::dynamicItemWithTTFLabel(aCancelBtnTitle, fontName.c_str(), messageFontSize, btnSize, btnBG_name.c_str(), NULL, this, menu_selector(VVAlertView::onBtnCancel), btn9patch_rect, 255); CCMenu *menu; if (aOtherBtnTitle == NULL) { menu = CCMenu::menuWithItems(btnCancel, NULL); } else { CCMenuItemSprite* btnOk = CCMenuItemDynamic::dynamicItemWithTTFLabel(aOtherBtnTitle, fontName.c_str(), messageFontSize, btnSize, btnBG_name.c_str(), NULL, this, menu_selector(VVAlertView::onBtnOk), btn9patch_rect, 255); menu = CCMenu::menuWithItems(btnCancel, btnOk, NULL); menu->alignItemsHorizontallyWithPadding(betweenBtnPadding); } menu->setTouchPriority(VVTouchPriorityMenuOnPopupLayer); addChild(bg); if (titleLabel) addChild(titleLabel); addChild(msgLabel); addChild(menu); if (titleLabel) totalHeight += titleLabel->getContentSize().height; totalHeight += msgLabel->getContentSize().height; totalHeight += btnCancel->getContentSize().height; totalHeight += centerPadding; totalHeight += messagePadding*2; totalHeight += borderPadding*2; float halfHeight = totalHeight/2; if (titleLabel) { titleLabel ->setPosition(ccp(0, halfHeight - borderPadding - titleLabel->getContentSize().height/2)); // -15 : top padding msgLabel ->setPosition(ccp(0, halfHeight - borderPadding - titleLabel->getContentSize().height - messagePadding - msgLabel->getContentSize().height/2 )); } else { msgLabel ->setPosition(ccp(0, halfHeight - borderPadding - msgLabel->getContentSize().height/2 )); } menu ->setPosition(ccp(0, -halfHeight + borderPadding + btnCancel->getContentSize().height/2)); bg->setContentSize(CCSizeMake(maxWidth, totalHeight)); // will be used for placing text field in the middle centerOfMargin = (msgLabel->getPosition().y + menu->getPosition().y)/2; return true; }
bool PanelLayer::init() { bool bRet = false; do { CC_BREAK_IF(! CCLayer::init()); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); // Settting and pause (Right Top) CCMenuItemImage* setting = CCMenuItemImage::create( STATIC_DATA_STRING("setting_normal"), STATIC_DATA_STRING("setting_selected"), this, menu_selector(PanelLayer::setting)); CC_BREAK_IF( !setting ); CCMenuItemImage* pause = CCMenuItemImage::create( STATIC_DATA_STRING("pause_normal"), STATIC_DATA_STRING("pause_selected"), this, menu_selector(PanelLayer::pause)); CC_BREAK_IF( !pause ); CCSize settingSize = setting->getContentSize(); CCSize pauseSize = pause->getContentSize(); CCMenu* menu = CCMenu::create(setting, pause, NULL); CC_BREAK_IF( !menu ); this->addChild(menu, 1, MENUTAG); menu->setPosition(CCPointMake(winSize.width-pauseSize.width * 3 / 2, winSize.height-pauseSize.height * 3 /4)); menu->alignItemsHorizontallyWithPadding(pauseSize.width / 3); // energy bar (Left Top) energyBar = ProgressBar::create(); CC_BREAK_IF( !energyBar ); CCSize barSize = energyBar->getContentSize(); energyBar->setPosition(ccp(barSize.width*0.52, winSize.height-barSize.height*0.58)); this->addChild(energyBar); // energy button(Left Top) eneygyButtonNormal = CCMenuItemImage::create( STATIC_DATA_STRING("ultimateButton_normal"), STATIC_DATA_STRING("ultimateButton_normal"), this, menu_selector(PanelLayer::useUltimate)); eneygyButtonFull = CCMenuItemImage::create( STATIC_DATA_STRING("ultimateButton_selected"), STATIC_DATA_STRING("ultimateButton_selected"), this, menu_selector(PanelLayer::useUltimate)); menuUltimate = CCMenu::create(eneygyButtonNormal, eneygyButtonFull, NULL); eneygyButtonFull->setVisible(false); this->addChild(menuUltimate); CCSize ultiSize = eneygyButtonNormal->getContentSize(); menuUltimate->setPosition(ccp(ultiSize.width*0.6, winSize.height-ultiSize.height*0.58)); // Pro propLeft = CCMenuItemImage::create( STATIC_DATA_STRING("prop_nothing"), STATIC_DATA_STRING("prop_nothing"), this, menu_selector(PanelLayer::useLeftPro)); propLeft->setTag(LEFT); Prop* prop = Prop::create(No_Prop); this->setLeftProp(prop); propRight = CCMenuItemImage::create( STATIC_DATA_STRING("prop_nothing"), STATIC_DATA_STRING("prop_nothing"), this, menu_selector(PanelLayer::useRightPro)); propRight->setTag(RIGHT); Prop* prop2 = Prop::create(No_Prop); this->setRightProp(prop2); menuProp = CCMenu::create(propLeft, propRight, NULL); this->addChild(menuProp); CCSize proSize = propLeft->getContentSize(); menuProp->setPosition(CCPointMake(proSize.width * 3 / 2, proSize.height * 0.618)); menuProp->alignItemsHorizontallyWithPadding(proSize.width / 3); leftPlaced = rightPlaced = false; bRet = true; } while (0); return bRet; }
bool HelloWorld::init() { bool bRet = false; do { CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); CC_BREAK_IF(! pCloseItem); pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20)); CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL); pMenu->setPosition(CCPointZero); CC_BREAK_IF(! pMenu); this->addChild(pMenu, 1); //解析tmx地图 map = CCTMXTiledMap::tiledMapWithTMXFile("0.tmx"); addChild(map); CCArray * pChildrenArray = map->getChildren(); CCSpriteBatchNode* child = NULL; CCObject* pObject = NULL; //遍历Tilemap的所有图层 CCARRAY_FOREACH(pChildrenArray, pObject) { child = (CCSpriteBatchNode*)pObject; if(!child) break; //给图层的纹理开启抗锯齿 child->getTexture()->setAntiAliasTexParameters(); } walkAnimation = new CCAnimation*[4]; walkAnimation[kDown] = createAnimationByDirection(kDown); walkAnimation[kRight] = createAnimationByDirection(kRight); walkAnimation[kLeft] = createAnimationByDirection(kLeft); walkAnimation[kUp] = createAnimationByDirection(kUp); //用frame0作为勇士的静态图 heroSprite = CCSprite::spriteWithSpriteFrame(walkAnimation[kDown]->getFrames()->getObjectAtIndex(0)); //heroSprite->setPosition(ccp(48, 48)); heroSprite->setAnchorPoint(CCPointZero); heroSprite->setPosition(positionForTileCoord(ccp(1, 11))); addChild(heroSprite); isHeroWalking = false; CCMenuItem *down = CCMenuItemFont::itemFromString("down", this, menu_selector(HelloWorld::menuCallBackMove)); CCMenuItem *left = CCMenuItemFont::itemFromString("left", this, menu_selector(HelloWorld::menuCallBackMove) ); CCMenuItem *right = CCMenuItemFont::itemFromString("right", this, menu_selector(HelloWorld::menuCallBackMove) ); CCMenuItem *up = CCMenuItemFont::itemFromString("up", this, menu_selector(HelloWorld::menuCallBackMove) ); CCMenu* menu = CCMenu::menuWithItems(down, left, right, up, NULL); //为了方便查找,给每个menuItem设置tag down->setTag(kDown); left->setTag(kLeft); right->setTag(kRight); up->setTag(kUp); //菜单项按间距50水平排列 menu->alignItemsHorizontallyWithPadding(50); addChild(menu); schedule(schedule_selector(HelloWorld::update)); bRet = true; } while (0);
bool LayerWin::init() { bool bRet = false; do { int curTitle = Global::shareGlobal()->curTitle; CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CC_BREAK_IF(!initWithColor(ccc4(250, 248, 239,255))); CCLabelTTF* label = CCLabelTTF::create(curTitle == 11 ? "YOU WIN!" : "GREAT!","Arial Bold",32, CCSize(visibleSize.width,visibleSize.height*0.7),kCCTextAlignmentCenter); CC_BREAK_IF(!label); label->setColor(ccc3(119,110,101)); label->setPosition(ccp(origin.x+visibleSize.width/2,origin.y+visibleSize.height/2)); this->addChild(label); float rectX = visibleSize.width*0.75; float rectY = rectX*0.45; ColorRect* pRect = ColorRect::create(ccc4(236, 196, 0, 255),rectX,rectY); pRect->setPosition(origin.x + (visibleSize.width-rectX)/2,origin.y+(visibleSize.height)/2); this->addChild(pRect); CCString *ssv = CCString::createWithFormat("%d",1 << curTitle); CCLabelTTF* scoreValue = CCLabelTTF::create(ssv->getCString(),"Arial Bold",32,CCSize(rectX,rectY), kCCTextAlignmentCenter); this->addChild(scoreValue); scoreValue->setPosition(ccp(pRect->getPositionX()+rectX*0.5,pRect->getPositionY()+rectY*0.3)); CCString *sst = CCString::createWithFormat("SCORE:%d",Global::shareGlobal()->curScore); CCLabelTTF* score = CCLabelTTF::create(sst->getCString(),"Arial Bold",8,CCSize(rectX,rectY*0.5), kCCTextAlignmentCenter); this->addChild(score); score->setPosition(ccp(pRect->getPositionX()+rectX*0.5,pRect->getPositionY())); float menuX = rectX*0.45; float menuY = menuX*0.3; TitleRect *titleBack = TitleRect::create(ccc4(187, 173, 160, 255),menuX,menuY,"Back"); CCMenuItemLabel *MenuBack = CCMenuItemLabel::create(titleBack,this,menu_selector(LayerWin::menuBack)); TitleRect *titleAgain = TitleRect::create(ccc4(187, 173, 160, 255),menuX,menuY,"Try again"); CCMenuItemLabel *MenuAgain = CCMenuItemLabel::create(titleAgain,this,menu_selector(LayerWin::menuAgain)); CCMenu *menu = CCMenu::create(MenuBack,MenuAgain,NULL); menu->alignItemsHorizontallyWithPadding(rectX*0.1); menu->setPositionY(origin.y+visibleSize.height*0.2); this->addChild(menu); bRet = true; }while(0); return bRet; }
bool FC_Intro::CreateMenu() { bool bRet = false; do { CCSize s = CCDirector::sharedDirector()->getWinSize(); // 언어에 따라서 버튼이미지 변경 char szNormal[260]; char szPressed[260]; char* szLang = LanguageUtil::getLanguageCode(); // 뒤로가기 버튼 CCMenuItemImage* pBackItem = CCMenuItemImage::create("common/home_game_button.png", "common/home_game_button_s.png", this, menu_selector(FC_Intro::menuClickCallback)); pBackItem->setTag(3); CCMenu* pBackMenu = CCMenu::create(); pBackMenu->addChild(pBackItem); pBackMenu->setPosition(ccp(19 + pBackItem->getContentSize().width/2 , s.height - 40)); this->addChild(pBackMenu, 100); ////////////////////////////////////////////////////////////////////////////////////////// // 시작버튼 sprintf(szNormal, "common/game/start_btn_%s.png", szLang); sprintf(szPressed, "common/game/start_pressed_btn_%s.png", szLang); CCMenuItemImage* pStartItem = CCMenuItemImage::create(szNormal, szPressed, this, menu_selector(FC_Intro::menuClickCallback)); pStartItem->setTag(4); CCMenu* pStartMenu = CCMenu::create(); pStartMenu->addChild(pStartItem); // menu가 Anchor point가 적용되지 않아서 계산해서 위치설정. pStartMenu->setPosition(ccp(s.width/2, START_BTN_MARGIN_B + pStartItem->getContentSize().height/2)); this->addChild(pStartMenu, 100); // 쉬움, 어려움 선택메뉴 sprintf(szNormal, "common/game/easy_btn_%s.png", szLang); sprintf(szPressed, "common/game/easy_pressed_btn_%s.png", szLang); m_pMenuItem1 = CCMenuItemImage::create(szNormal, szPressed, this, menu_selector(FC_Intro::menuClickCallback)); m_pMenuItem1->setTag(1); if ( LV_EASY == m_nGameLevel ) m_pMenuItem1->selected(); CC_BREAK_IF(! m_pMenuItem1); sprintf(szNormal, "common/game/difficulty_btn_%s.png", szLang); sprintf(szPressed, "common/game/difficulty_pressed_btn_%s.png", szLang); m_pMenuItem2 = CCMenuItemImage::create(szNormal, szPressed, this, menu_selector(FC_Intro::menuClickCallback)); m_pMenuItem2->setTag(2); if ( LV_HARD == m_nGameLevel ) m_pMenuItem2->selected(); CC_BREAK_IF(! m_pMenuItem2); CCMenu* pMenu = CCMenu::create(); pMenu->addChild(m_pMenuItem1, 1); pMenu->addChild(m_pMenuItem2, 1); // menu가 Anchor point가 적용되지 않아서 계산해서 위치설정. int nBtnWidth = m_pMenuItem1->getContentSize().width; int nBtnHeight = m_pMenuItem1->getContentSize().height; pMenu->setPosition(ccp(LEVEL_BTN_MARGIN_L + nBtnWidth, LEVEL_BTN_MARGIN_B + nBtnHeight/2)); pMenu->alignItemsHorizontallyWithPadding(0); CC_BREAK_IF(! pMenu); this->addChild(pMenu,100); bRet = true; } while(0); return bRet; }
bool InGamePowers::init() { if (!CCLayer::init()) { return false; } mPowerCost_1 = 100; mPowerCost_2 = 50; mPowerCost_3 = 50; mPowerCoolDown_1 = 15; mPowerCoolDown_2 = 10; mPowerCoolDown_3 = 10; // Ask director the window size. CCSize winSize = CCDirector::sharedDirector()->getWinSize(); // Create the score label. // __pScoreLabel = CCLabelTTF::create("Score 0", "Arial", 30); // Position the label on the right side of the screen. // __pScoreLabel->setPosition(ccp(winSize.width - 100, winSize.height - 20)); // Add the label as a child to this layer. // addChild(__pScoreLabel, 1); // The base of button //------------------------------------------------------------------------------------------------------------ // The new spell stuff !!! std::vector<int> theActiveSpells = User::getInstance()->getItemDataManager().getActiveItems(); button_1 = NULL; button_2 = NULL; // Create the 1st button if(theActiveSpells.size()>0) { // Get the real data from spell mButtonSpell_1 = User::getInstance()->getItemDataManager().getSpellByID(theActiveSpells[0]); button_1 = CCMenuItemImage::create( mButtonSpell_1.icon_path.c_str(), mButtonSpell_1.icon_path.c_str(), this, menu_selector(InGamePowers::onButton_1)); button_1->setOpacity(255); } if(theActiveSpells.size()>1) { mButtonSpell_2 = User::getInstance()->getItemDataManager().getSpellByID(theActiveSpells[1]); button_2 = CCMenuItemImage::create( mButtonSpell_2.icon_path.c_str(), mButtonSpell_2.icon_path.c_str(), this, menu_selector(InGamePowers::onButton_2)); button_2->setOpacity(128); } // Lets create the menu for buttons CCMenu* mainMenu; if(button_1 != NULL && button_2 == NULL){ mainMenu = CCMenu::create(button_1, NULL); } else{ mainMenu = CCMenu::create(button_1,button_2, NULL); } mainMenu->alignItemsHorizontallyWithPadding(10); mainMenu->setPosition(ccp(0,20)); // mainMenu->setOpacity(0); addChild(mainMenu, 1); OnResetAllVars(); return true; //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ //The button place in world /* mButton_1_Base = CCSprite::create("small_dot_red.png"); mButton_1_Base->setPosition(ccp(-92,20)); addChild(mButton_1_Base); // The bottom of button mButton_1_TopBack = CCSprite::create("PowerButtons/PB_TopBack.png"); mButton_1_TopBack->setPosition(ccp(mButton_1_Base->getContentSize().width/2, mButton_1_Base->getContentSize().height/2)); mButton_1_Base->addChild(mButton_1_TopBack,-1); // The progress bar CCSprite* aProgressSprite = CCSprite::create("PowerButtons/PB_Progress.png"); mButton_1_Progress = CCProgressTimer::create(aProgressSprite); mButton_1_Progress->setType(kCCProgressTimerTypeRadial); mButton_1_Progress->setPercentage(100); mButton_1_Progress->setPosition(ccp(mButton_1_Base->getContentSize().width/2, mButton_1_Base->getContentSize().height/2)); mButton_1_Base->addChild(mButton_1_Progress); // The above stuff mButton_1_Top = CCSprite::create("PowerButtons/PB_Top.png"); mButton_1_Top->setPosition(ccp(mButton_1_Base->getContentSize().width/2, mButton_1_Base->getContentSize().height/2)); mButton_1_Base->addChild(mButton_1_Top); // The icon - can be custom mButton_1_Icon = CCSprite::create("PowerButtons/PB_Ghost_Icon.png"); mButton_1_Icon->setPosition(ccp(mButton_1_Top->getContentSize().width/2, mButton_1_Top->getContentSize().height/2)); mButton_1_Icon->setColor(ccGRAY); mButton_1_Top->addChild(mButton_1_Icon); // The procent of load mButton_1_Load = CCLabelBMFont::create("100%", "PowerButtons/PB_Font.fnt", mButton_1_Top->getContentSize().width, kCCTextAlignmentCenter); mButton_1_Load->setPosition(ccp(mButton_1_Base->getContentSize().width/2+2,mButton_1_Base->getContentSize().height/2-20)); mButton_1_Load->setScale(0.75f); mButton_1_Load->setVisible(false); mButton_1_Base->addChild(mButton_1_Load,1); // This is the cost bar mButton_1_Bottom = CCSprite::create("PowerButtons/PB_Bottom.png"); mButton_1_Base->addChild(mButton_1_Bottom); mButton_1_Bottom->setPosition(ccp(mButton_1_Base->getContentSize().width/2, mButton_1_Base->getContentSize().height/2-45)); // Add the text field for this button !!! Cost of crystals mButton_1_Cost =CCLabelBMFont::create("100", "PowerButtons/PB_Font.fnt", mButton_1_Bottom->getContentSize().width, kCCTextAlignmentCenter); mButton_1_Cost->setPosition(ccp(mButton_1_Bottom->getContentSize().width/2-12,mButton_1_Bottom->getContentSize().height/2-4)); mButton_1_Cost->setColor(ccc3(183, 183, 183)); mButton_1_Bottom->addChild(mButton_1_Cost); //------------------------------------------------------------------------------------------------------------ // The next button !!! //------------------------------------------------------------------------------------------------------------ //The button place in world mButton_2_Base = CCSprite::create("small_dot_red.png"); mButton_2_Base->setPosition(ccp(0,20)); addChild(mButton_2_Base); // The bottom of button mButton_2_TopBack = CCSprite::create("PowerButtons/PB_TopBack.png"); mButton_2_TopBack->setPosition(ccp(mButton_2_Base->getContentSize().width/2, mButton_2_Base->getContentSize().height/2)); mButton_2_Base->addChild(mButton_2_TopBack,-1); // The progress bar aProgressSprite = CCSprite::create("PowerButtons/PB_Progress.png"); mButton_2_Progress = CCProgressTimer::create(aProgressSprite); mButton_2_Progress->setType(kCCProgressTimerTypeRadial); mButton_2_Progress->setPercentage(100); mButton_2_Progress->setPosition(ccp(mButton_2_Base->getContentSize().width/2, mButton_2_Base->getContentSize().height/2)); mButton_2_Base->addChild(mButton_2_Progress); // The above stuff mButton_2_Top = CCSprite::create("PowerButtons/PB_Top.png"); mButton_2_Top->setPosition(ccp(mButton_2_Base->getContentSize().width/2, mButton_2_Base->getContentSize().height/2)); mButton_2_Base->addChild(mButton_2_Top); // The icon - can be custom mButton_2_Icon = CCSprite::create("PowerButtons/PB_Attack_Icon.png"); mButton_2_Icon->setPosition(ccp(mButton_2_Top->getContentSize().width/2, mButton_2_Top->getContentSize().height/2)); mButton_2_Icon->setColor(ccGRAY); mButton_2_Top->addChild(mButton_2_Icon); // The procent of load mButton_2_Load = CCLabelBMFont::create("100%", "PowerButtons/PB_Font.fnt", mButton_2_Top->getContentSize().width, kCCTextAlignmentCenter); mButton_2_Load->setPosition(ccp(mButton_2_Base->getContentSize().width/2+2,mButton_2_Base->getContentSize().height/2-20)); mButton_2_Load->setScale(0.75f); mButton_2_Load->setVisible(false); mButton_2_Base->addChild(mButton_2_Load,1); // This is the cost bar mButton_2_Bottom = CCSprite::create("PowerButtons/PB_Bottom.png"); mButton_2_Base->addChild(mButton_2_Bottom); mButton_2_Bottom->setPosition(ccp(mButton_2_Base->getContentSize().width/2, mButton_2_Base->getContentSize().height/2-45)); // Add the text field for this button !!! Cost of crystals mButton_2_Cost =CCLabelBMFont::create("50", "PowerButtons/PB_Font.fnt", mButton_2_Bottom->getContentSize().width, kCCTextAlignmentCenter); mButton_2_Cost->setPosition(ccp(mButton_2_Bottom->getContentSize().width/2-12,mButton_2_Bottom->getContentSize().height/2-4)); mButton_2_Cost->setColor(ccc3(183, 183, 183)); mButton_2_Bottom->addChild(mButton_2_Cost); //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ //The button place in world mButton_3_Base = CCSprite::create("small_dot_red.png"); mButton_3_Base->setPosition(ccp(92,20)); addChild(mButton_3_Base); // The bottom of button mButton_3_TopBack = CCSprite::create("PowerButtons/PB_TopBack.png"); mButton_3_TopBack->setPosition(ccp(mButton_3_Base->getContentSize().width/2, mButton_3_Base->getContentSize().height/2)); mButton_3_Base->addChild(mButton_3_TopBack,-1); // The progress bar aProgressSprite = CCSprite::create("PowerButtons/PB_Progress.png"); mButton_3_Progress = CCProgressTimer::create(aProgressSprite); mButton_3_Progress->setType(kCCProgressTimerTypeRadial); mButton_3_Progress->setPercentage(100); mButton_3_Progress->setPosition(ccp(mButton_3_Base->getContentSize().width/2, mButton_3_Base->getContentSize().height/2)); mButton_3_Base->addChild(mButton_3_Progress); // The above stuff mButton_3_Top = CCSprite::create("PowerButtons/PB_Top.png"); mButton_3_Top->setPosition(ccp(mButton_3_Base->getContentSize().width/2, mButton_3_Base->getContentSize().height/2)); mButton_3_Base->addChild(mButton_3_Top); // The icon - can be custom mButton_3_Icon = CCSprite::create("PowerButtons/PB_Freeze_Icon.png"); mButton_3_Icon->setPosition(ccp(mButton_3_Top->getContentSize().width/2, mButton_3_Top->getContentSize().height/2)); mButton_3_Icon->setColor(ccGRAY); mButton_3_Top->addChild(mButton_3_Icon); // The procent of load mButton_3_Load = CCLabelBMFont::create("100%", "PowerButtons/PB_Font.fnt", mButton_3_Top->getContentSize().width, kCCTextAlignmentCenter); mButton_3_Load->setPosition(ccp(mButton_3_Base->getContentSize().width/2+2,mButton_3_Base->getContentSize().height/2-20)); mButton_3_Load->setScale(0.75f); mButton_3_Load->setVisible(false); mButton_3_Base->addChild(mButton_3_Load,1); // This is the cost bar mButton_3_Bottom = CCSprite::create("PowerButtons/PB_Bottom.png"); mButton_3_Base->addChild(mButton_3_Bottom); mButton_3_Bottom->setPosition(ccp(mButton_3_Base->getContentSize().width/2, mButton_3_Base->getContentSize().height/2-45)); // Add the text field for this button !!! Cost of crystals mButton_3_Cost =CCLabelBMFont::create("50", "PowerButtons/PB_Font.fnt", mButton_3_Bottom->getContentSize().width, kCCTextAlignmentCenter); mButton_3_Cost->setPosition(ccp(mButton_3_Bottom->getContentSize().width/2-12,mButton_3_Bottom->getContentSize().height/2-4)); mButton_3_Cost->setColor(ccc3(183, 183, 183)); mButton_3_Bottom->addChild(mButton_3_Cost); //------------------------------------------------------------------------------------------------------------ //Add the 3 buttons button_1 = CCMenuItemImage::create( "button_freez.png", "button_freez.png", this, menu_selector(InGamePowers::onButton_1)); button_2 = CCMenuItemImage::create( "button_electro.png", "button_electro.png", this, menu_selector(InGamePowers::onButton_2)); button_3 = CCMenuItemImage::create( "Charges_Machine.png", "Charges_Machine.png", this, menu_selector(InGamePowers::onButton_3)); CCMenu* mainMenu = CCMenu::create(button_1,button_2,button_3, NULL); mainMenu->alignItemsHorizontallyWithPadding(10); mainMenu->setPosition(ccp(0,20)); mainMenu->setOpacity(0); addChild(mainMenu, 1); // The other stuff // mGameScene = dynamic_cast<GameScene*>(this->getParent()); OnResetAllVars(); */ return true; }
bool CCAlertView::init(const char *_title, const char *_message, const char *_cancel, const char *_ok, CCObject *_object, SEL_CallFuncO _selector1, SEL_CallFuncO _selector2) { this->setTouchPriority(0); object = _object; selector1 = _selector1; selector2 = _selector2; CCSize size = CCDirector::sharedDirector()->getWinSize(); this->setTouchEnabled(true); this->setPosition(ccp(size.width / 2.0f, size.height / 2.0f)); CCSprite *bgSprite = CCSprite::create(getResPath("images/mainmenuScene/blank.png")); bgSprite->setTextureRect(CCRect(0, 0, size.width, size.height)); bgSprite->setColor(ccc3(0, 0, 0)); bgSprite->setOpacity(0); this->addChild(bgSprite, 1000); CCSprite *alertViewSprite = CCSprite::create(getResPath("images/mainmenuScene/alert_bg.png")); this->addChild(alertViewSprite, 1001); CCMenuItemImage *button1 = CCMenuItemImage::create(getResPath("images/mainmenuScene/btn_ok_nor.png"), getResPath("images/mainmenuScene/btn_ok_prs.png"), this, menu_selector(CCAlertView::button1Callback)); CCMenuItemImage *button2 = CCMenuItemImage::create(getResPath("images/mainmenuScene/btn_cancel_nor.png"), getResPath("images/mainmenuScene/btn_cancel_prs.png"), this, menu_selector(CCAlertView::button2Callback)); // button1->setOpacity(180); // button2->setOpacity(180); CCMenu *alertMenu = CCMenu::create(button1, button2, NULL); alertMenu->alignItemsHorizontallyWithPadding(20); alertMenu->setPosition(ccp(alertViewSprite->getContentSize().width / 2.0f, (button1->getContentSize().height / 2.0f))); alertViewSprite->addChild(alertMenu); //80,150 CCLabelTTF *titleLabel = CCLabelTTF::create(_title, STANDARD_FONT, 70); titleLabel->setAnchorPoint(CCPoint(0.5, 1.0)); titleLabel->setPosition(ccp(alertViewSprite->getContentSize().width / 2.0f, alertViewSprite->getContentSize().height - 20 * SCALE)); alertViewSprite->addChild(titleLabel); CCLabelTTF *messageLabel = CCLabelTTF::create(_message, STANDARD_FONT, 40, CCSizeMake(alertViewSprite->getContentSize().width - 50 * SCALE, 0), kCCTextAlignmentCenter); messageLabel->setAnchorPoint(CCPoint(0.5, 1.0)); messageLabel->setPosition(ccp(alertViewSprite->getContentSize().width / 2.0f, titleLabel->getPositionY() - 100)); alertViewSprite->addChild(messageLabel); CCLabelTTF *cancelLabel = CCLabelTTF::create(_cancel, STANDARD_FONT, 18); cancelLabel->setPosition(ccp(button2->getContentSize().width / 2.0f, button2->getContentSize().height / 2.0f)); button1->addChild(cancelLabel); CCLabelTTF *OKlabel = CCLabelTTF::create(_ok, STANDARD_FONT, 18); OKlabel->setPosition(ccp(button1->getContentSize().width / 2.0f, button1->getContentSize().height / 2.0f)); button2->addChild(OKlabel); bgSprite->runAction(CCFadeTo::create(0.1f, 150)); // CCFiniteTimeAction *scale1 = CCScaleTo::create(0.15f, 1.1f); // CCFiniteTimeAction *scale2 = CCScaleTo::create(0.1f, 0.9f); // CCFiniteTimeAction *scale3 = CCScaleTo::create(0.05f, 1.0f); alertViewSprite->setScaleX(SCALEX); alertViewSprite->setScaleY(SCALEY); //alertViewSprite->runAction(CCSequence::create(scale1, scale2, scale3, NULL)); return true; }
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); }
void PauseLayer::addStatsLayer() { statsLayer = CCLayer::create(); statsLayer->setPosition(ccp(winSize.width * 0, winSize.height * 0)); float scale = Utility::isIPad() ? 1 : 0.7; CCLabelBMFont *labelObj = CCLabelBMFont::create("stats", kFontChubby, 0); labelObj->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.93)); labelObj->setScale(scale); statsLayer->addChild(labelObj, 2); CCLabelBMFont *thisGameLabel = CCLabelBMFont::create("this game", kFontChubby, 0); thisGameLabel->setScale(scale); thisGameItem = CCMenuItemLabel::create(thisGameLabel, this, menu_selector(PauseLayer::menuCallBack) ); thisGameItem->setContentSize(CCSize(thisGameItem->getContentSize() * scale)); thisGameItem->setTag(7); CCLabelBMFont *slashLabel = CCLabelBMFont::create("/", kFontChubby, 0); slashLabel->setScale(scale); CCMenuItemLabel *slashItem = CCMenuItemLabel::create(slashLabel, this, menu_selector(PauseLayer::menuCallBack) ); slashItem->setContentSize(CCSize(slashItem->getContentSize() * scale)); CCLabelBMFont *recordsLabel = CCLabelBMFont::create("records", kFontChubby, 0); recordsLabel->setScale(scale); recordsItem = CCMenuItemLabel::create(recordsLabel, this, menu_selector(PauseLayer::menuCallBack) ); recordsItem->setContentSize(CCSize(recordsItem->getContentSize() * scale)); recordsItem->setTag(8); CCMenu *thisGameRecordsMenu = CCMenu::create(thisGameItem, slashItem, recordsItem, NULL); thisGameRecordsMenu->alignItemsHorizontallyWithPadding(winSize.width * 0.01); thisGameRecordsMenu->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.8)); statsLayer->addChild(thisGameRecordsMenu, 2); createButton("btnObj.png", 6, ccp(winSize.width * 0.30, winSize.height * 0.93)); const char *score = NULL; const char *distance = NULL; const char *wallsSmashed = NULL; const char *tightSqueezes = NULL; const char *longestGamePlayed = NULL; if (isCallFromRecords) { CCSprite *coinSprite = CCSprite::createWithSpriteFrameName("coin_0.png"); coinSprite->setPosition(ccp(winSize.width * 0.75, winSize.height * 0.65)); statsLayer->addChild(coinSprite, 2); const char *totalCoins = CCString::createWithFormat("%d", gLayer->coinScore)->getCString(); createLabelForStats("", totalCoins, ccp(coinSprite->getPositionX() + winSize.width * 0.05, coinSprite->getPositionY()), statsLayer); score = CCString::createWithFormat("%d", gLayer->score)->getCString(); distance = CCString::createWithFormat("%d meters", gLayer->distance)->getCString(); wallsSmashed = CCString::createWithFormat("%d", gLayer->wallSmashed)->getCString(); tightSqueezes = CCString::createWithFormat("%d", Utility::getTotalTightSqueezes())->getCString(); longestGamePlayed = CCString::createWithFormat("%02dm%02ds", gLayer->minute, gLayer->seconds)->getCString(); } else { const char *playerName = CCString::createWithFormat("(%s)", Utility::getPlayerName(0)->getCString())->getCString(); createLabelForStats("", playerName, ccp(winSize.width * 0.65, winSize.height * 0.65), statsLayer); int longestGame = Utility::getLongestGame(); int min = longestGame / 60; int sec = longestGame % 60; longestGamePlayed = CCString::createWithFormat("%02dm%02ds", min, sec)->getCString(); score = CCString::createWithFormat("%d", Utility::getPlayerScore(0))->getCString(); distance = CCString::createWithFormat("%d meters", Utility::getLongestDistance())->getCString(); wallsSmashed = CCString::createWithFormat("%d", Utility::getTotalWallSmashedLifeTime())->getCString(); tightSqueezes = CCString::createWithFormat("%d", Utility::getTotalTightSqueezesLifeTime())->getCString(); } createLabelForStats("score:", score, ccp(winSize.width * 0.55, winSize.height * 0.65), statsLayer); createLabelForStats("distance:", distance, ccp(winSize.width * 0.55, winSize.height * 0.55), statsLayer); createLabelForStats("walls smashed:", wallsSmashed, ccp(winSize.width * 0.55, winSize.height * 0.45), statsLayer); createLabelForStats("tight squeezes:", tightSqueezes, ccp(winSize.width * 0.55, winSize.height * 0.35), statsLayer); createLabelForStats("game time:", longestGamePlayed, ccp(winSize.width * 0.55, winSize.height * 0.25), statsLayer); addChild(statsLayer, 1); }
bool GameMain::init(){ if(!CCLayer::init()){ return false; } CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); frameCache->addSpriteFramesWithFile((sceneDir+"mainscene1-hd.plist").c_str()); CCSpriteBatchNode* mainSceneBatch = CCSpriteBatchNode::createWithTexture(SPRITE(mainbg.png)->getTexture()); addChild(mainSceneBatch); //背景图片 CCSprite* mainBg = SPRITE(mainbg.png); CCPoint centerPoint = ccp(winSize.width/2,winSize.height/2); mainBg->setPosition(centerPoint); mainSceneBatch->addChild(mainBg); //云彩 CCSprite* cloud1 = SPRITE(cloud1.png); CCSprite* cloud2 = SPRITE(cloud2.png); cloud1->setPosition(ccp(-100,winSize.height-100)); cloud2->setPosition(ccp(-500,winSize.height-200)); CCActionInterval* cloud1Move = CCMoveTo::create(70,ccp(1700,winSize.height-100)); CCActionInterval* cloud2Move = CCMoveTo::create(70,ccp(1300,winSize.height-200)); cloud1->runAction(cloud1Move); cloud2->runAction(cloud2Move); cloud1->setColor(ccWHITE); cloud2->setColor(ccWHITE); ccBlendFunc bf = {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}; mainSceneBatch->setBlendFunc(bf); cloud1->setBlendFunc(bf); cloud2->setBlendFunc(bf); mainSceneBatch->addChild(cloud1); mainSceneBatch->addChild(cloud2); carrotNode = CCNode::create(); //萝卜 CCSprite* carrot = SPRITE(carrot.png); carrot->setAnchorPoint(ccp(0.5,0)); carrot->setPosition(CCPointZero); CCPoint leafPoint = ccp(0,carrot->getContentSize().height-50); //leaf CCSprite* carrotLeaf1 = SPRITE(leaf-1.png); CCSprite* carrotLeaf2 = SPRITE(leaf-2.png); CCSprite* carrotLeaf3 = SPRITE(leaf-3.png); carrotLeaf1->setAnchorPoint(ccp(1,0)); carrotLeaf2->setAnchorPoint(ccp(0.5,0)); carrotLeaf3->setAnchorPoint(ccp(0,0)); carrotLeaf1->setPosition(leafPoint); carrotLeaf2->setPosition(leafPoint); carrotLeaf3->setPosition(leafPoint); carrotNode->addChild(carrotLeaf1); carrotNode->addChild(carrotLeaf3); carrotNode->addChild(carrotLeaf2); carrotNode->addChild(carrot); carrotNode->setPosition(ccp(centerPoint.x,centerPoint.y-50)); carrotNode->setScale(0); CCActionInterval* scaleAction = CCScaleTo::create(0.3,1,1); CCActionInterval* delayRun = CCDelayTime::create(0.3); CCSequence* carrotNodeSeq = CCSequence::create(delayRun,scaleAction,NULL); addChild(carrotNode); //Logo图片 CCSprite* mainBg_CN = SPRITE(mainbg_CN.png); mainBg_CN->setPosition(centerPoint); addChild(mainBg_CN); CCSprite* bird = SPRITE(bird.png); bird->setPosition(ccp(VisibleRect::leftTop().x+200,VisibleRect::leftTop().y-150)); CCActionInterval* birdUp = CCMoveBy::create(2,ccp(0,35)); CCActionInterval* birdDown = birdUp->reverse(); CCSequence* birdAction = CCSequence::create(birdUp,birdDown,NULL); bird->runAction(CCRepeatForever::create(birdAction)); mainSceneBatch->addChild(bird); //冒险模式 Boss模式 宠物窝 CCMenuItemSprite* adventureMode = CCMenuItemSprite::create(SPRITE(btn_adventure_normal_CN.png), SPRITE(btn_adventure_pressed_CN.png),SceneManager::shareSceneManager(),menu_selector(SceneManager::toAdventureScene)); CCMenuItemSprite* bossMode = CCMenuItemSprite::create(SPRITE(btn_boss_normal_CN.png), SPRITE(btn_boss_pressed_CN.png)); CCMenuItemSprite* nest = CCMenuItemSprite::create(SPRITE(btn_nest_normal_CN.png), SPRITE(btn_nest_pressed_CN.png)); CCMenu* mainMenu = CCMenu::create(adventureMode,bossMode,nest,NULL); mainMenu->alignItemsHorizontallyWithPadding(20); mainMenu->setPosition(ccp(VisibleRect::center().x,VisibleRect::bottom().y+100)); addChild(mainMenu); //设置和帮助菜单 CCMenuItemSprite* settingBtn = CCMenuItemSprite::create(SPRITE(btn_setting_normal.png),SPRITE(btn_setting_pressed.png), SceneManager::shareSceneManager(),menu_selector(SceneManager::toSettingScene)); CCMenuItemSprite* helpBtn = CCMenuItemSprite::create(SPRITE(btn_help_normal.png),SPRITE(btn_help_pressed.png), SceneManager::shareSceneManager(),menu_selector(SceneManager::toHelpScene)); CCMenu* setMenu = CCMenu::create(settingBtn,helpBtn,NULL); setMenu->alignItemsHorizontallyWithPadding(450); setMenu->setPosition(ccp(VisibleRect::center().x,VisibleRect::center().y-95)); addChild(setMenu); //萝卜叶子的动画 CCActionInterval* shake = CCRotateBy::create(0.1,10); CCActionInterval* shakeBack = shake->reverse(); CCActionInterval* nextDelay = CCDelayTime::create(3); CCActionInterval* repeatDelay = CCDelayTime::create(1); CCCallFunc* callBack = CCCallFunc::create(this,callfunc_selector(GameMain::shakeLeaf)); CCSequence* shakeSeq = CCSequence::create(shake,shakeBack,shake,shakeBack,nextDelay,callBack,repeatDelay,NULL); carrotLeaf2->setTag(kLeaf2); carrotNode->runAction(carrotNodeSeq); carrotLeaf3->runAction(CCRepeatForever::create(shakeSeq)); return true; }
KDbool MenuLayer::init ( KDvoid ) { if ( !CCLayer::init ( ) ) { return KD_FALSE; } m_nIndexText = 0; CCSprite* pBackground = CCSprite::create ( "Image 816 at frame 10.jpg" ); pBackground->setScale ( IOSSCALE ); pBackground->setPosition ( ccpMid ( m_tContentSize ) ); this->addChild ( pBackground ); CCMenuItemFont::setFontName ( "Arial Bold.ttf" ); CCMenuItemFont::setFontSize ( 18 ); CCMenuItem* pItemAchievement = CCMenuItemFont::create ( "Achievement" ); CCMenuItem* pItemLeaderboard = CCMenuItemFont::create ( "Leaderboard" ); CCMenuItem* pItemGetProps = CCMenuItemFont::create ( "GetProps" ); CCMenuItem* pItemPlay = CCMenuItemImage::create ( "Image 822 at frame 10.jpg", "Image 823 alpha channel at frame 10.png", this, menu_selector ( MenuLayer::playGame ) ); CCMenu* pMenu = CCMenu::create ( pItemAchievement, pItemLeaderboard, pItemGetProps, pItemPlay, KD_NULL ); pMenu->alignItemsHorizontallyWithPadding ( 18 ); pMenu->setPosition ( m_tContentSize.cx / 2, m_tContentSize.cy / 2 - 50 ); this->addChild ( pMenu ); m_pTelScope = TeleScope::create ( ); m_pTelScope->setPosition ( ccp ( 80, 60 ) ); m_pTelScope->setOpacity ( 0 ); pBackground->addChild ( m_pTelScope, 1 ); m_aTexts [ 0 ] = CCSprite::create ( "Image 817 at frame 10.jpg" ); m_aTexts [ 1 ] = CCSprite::create ( "Image 818 at frame 10.jpg" ); m_aTexts [ 2 ] = CCSprite::create ( "Image 819 at frame 10.jpg" ); m_aTexts [ 3 ] = CCSprite::create ( "Image 820 at frame 10.jpg" ); m_aTexts [ 0 ]->setPosition ( ccp ( 156 / 2 , 264 / 2 ) ); m_aTexts [ 1 ]->setPosition ( ccp ( 156 / 2 + 40, 264 / 2 ) ); m_aTexts [ 2 ]->setPosition ( ccp ( 156 / 2 + 80, 264 / 2 ) ); m_aTexts [ 3 ]->setPosition ( ccp ( 156 / 2 + 120, 264 / 2 ) ); m_aTexts [ 0 ]->setOpacity ( 0 ); m_aTexts [ 1 ]->setOpacity ( 0 ); m_aTexts [ 2 ]->setOpacity ( 0 ); m_aTexts [ 3 ]->setOpacity ( 0 ); pBackground->addChild ( m_aTexts [ 0 ] ); pBackground->addChild ( m_aTexts [ 1 ] ); pBackground->addChild ( m_aTexts [ 2 ] ); pBackground->addChild ( m_aTexts [ 3 ] ); m_aHoles [ 0 ] = CCSprite::create ( "Image 824 at frame 10.jpg" ); m_aHoles [ 1 ] = CCSprite::create ( "Image 824 at frame 10.jpg" ); m_aHoles [ 2 ] = CCSprite::create ( "Image 824 at frame 10.jpg" ); m_aHoles [ 3 ] = CCSprite::create ( "Image 824 at frame 10.jpg" ); m_aHoles [ 0 ]->setOpacity ( 0 ); m_aHoles [ 1 ]->setOpacity ( 0 ); m_aHoles [ 2 ]->setOpacity ( 0 ); m_aHoles [ 3 ]->setOpacity ( 0 ); m_aHoles [ 0 ]->setPosition ( ccp ( 58, 142 ) ); m_aHoles [ 1 ]->setPosition ( ccp ( 88, 112 ) ); m_aHoles [ 2 ]->setPosition ( ccp ( 226, 105 ) ); m_aHoles [ 3 ]->setPosition ( ccp ( 178, 132 ) ); pBackground->addChild ( m_aHoles [ 0 ] ); pBackground->addChild ( m_aHoles [ 1 ] ); pBackground->addChild ( m_aHoles [ 2 ] ); pBackground->addChild ( m_aHoles [ 3 ] ); SimpleAudioEngine::sharedEngine ( )->preloadEffect ( "Sound 1 at frame 10.mp3" ); SimpleAudioEngine::sharedEngine ( )->preloadEffect ( "Sound 5 at frame 10.mp3" ); SimpleAudioEngine::sharedEngine ( )->preloadEffect ( "Sound 3 at frame 10.mp3" ); return KD_TRUE; }