//------------------------------------------------------------------ // // MenuLayer2 // //------------------------------------------------------------------ MenuLayer2::MenuLayer2() { for( int i=0;i < 2;i++ ) { CCMenuItemImage* item1 = CCMenuItemImage::create(s_PlayNormal, s_PlaySelect, this, menu_selector(MenuLayer2::menuCallback)); CCMenuItemImage* item2 = CCMenuItemImage::create(s_HighNormal, s_HighSelect, this, menu_selector(MenuLayer2::menuCallbackOpacity) ); CCMenuItemImage* item3 = CCMenuItemImage::create(s_AboutNormal, s_AboutSelect, this, menu_selector(MenuLayer2::menuCallbackAlign) ); item1->setScaleX( 1.5f ); item2->setScaleX( 0.5f ); item3->setScaleX( 0.5f ); CCMenu* menu = CCMenu::create(item1, item2, item3, NULL); CCSize s = CCDirector::sharedDirector()->getWinSize(); menu->setPosition(ccp(s.width/2, s.height/2)); menu->setTag( kTagMenu ); addChild(menu, 0, 100+i); m_centeredMenu = menu->getPosition(); } m_alignedH = true; alignMenusH(); }
void StoryWorld::leafletChoiceHandler(CCObject *sender) { int choice = ((CCNode *)sender)->getTag(); switch (choice) { case fChoice: { removeChildByTag(2); removeChildByTag(3); CCSprite *blackBG = CCSprite::create(LEAFLET_IMG_PATH); blackBG->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/2)); blackBG->setScale(1); blackBG->setTag(21); addChild(blackBG, 2); CCMenuItemImage *start = CCMenuItemImage::create(LEAFLET_CLOSE_IMG_PATH, LEAFLET_CLOSE_IMG_PATH, this, menu_selector(StoryWorld::menuLeafletsCloseCallback)); start->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width-40, CCDirector::sharedDirector()->getVisibleSize().height-40)); CCMenu* pMenu = CCMenu::create(start, NULL); pMenu->setPosition(CCPointZero); pMenu->setTag(23); addChild(pMenu, 4); } return; case sChoice: default:{ specialPartSwitchCase('1'); } return; } }
void RPGStartSceneLayer::showMainMenu() { CCMenu *mainMenu = CCMenu::create(); mainMenu->setAnchorPoint(CCPointZero); mainMenu->setPosition(CCPointZero); mainMenu->setTag(kRPGStartSceneLayerTagMainMenu); this->addChild(mainMenu); CCString *menuStartStr = (CCString*)this->m_stringList->objectForKey("mainmenu_start"); CCLabelTTF *menuStartLabel = CCLabelTTF::create(OzgCCUtility::generalString(menuStartStr->getCString()).c_str(), "FZCuYuan-M03S", 28, CCSizeMake(120, 40), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter); CCString *menuRestartStr = (CCString*)this->m_stringList->objectForKey("mainmenu_restart"); CCLabelTTF *menuRestartLabel = CCLabelTTF::create(OzgCCUtility::generalString(menuRestartStr->getCString()).c_str(), "FZCuYuan-M03S", 28, CCSizeMake(120, 40), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter); CCString *menuSettingsStr = (CCString*)this->m_stringList->objectForKey("mainmenu_settings"); CCLabelTTF *menuSettingsLabel = CCLabelTTF::create(OzgCCUtility::generalString(menuSettingsStr->getCString()).c_str(), "FZCuYuan-M03S", 28, CCSizeMake(120, 40), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter); CCMenuItemLabel *menuStart = CCMenuItemLabel::create(menuStartLabel, this, menu_selector(RPGStartSceneLayer::onMenu)); menuStart->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width / 2, 230)); menuStart->setTag(kRPGStartSceneLayerTagMainMenuItemStart); mainMenu->addChild(menuStart); CCMenuItemLabel *menuRestart = CCMenuItemLabel::create(menuRestartLabel, this, menu_selector(RPGStartSceneLayer::onMenu)); menuRestart->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width / 2, 170)); menuRestart->setTag(kRPGStartSceneLayerTagMainMenuItemRestart); mainMenu->addChild(menuRestart); CCMenuItemLabel *menuSettings = CCMenuItemLabel::create(menuSettingsLabel, this, menu_selector(RPGStartSceneLayer::onMenu)); menuSettings->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width / 2, 110)); menuSettings->setTag(kRPGStartSceneLayerTagMainMenuItemSettings); mainMenu->addChild(menuSettings); }
void GameOverLayer::createPlayAgainButton() { // Create the startButton CCSprite *playAgainButtonSpriteUp = CCSprite::createWithSpriteFrameName("playagain_button.png"); CCSprite *playAgainButtonSpriteDown = CCSprite::createWithSpriteFrameName("playagain_button.png"); // Scale the down to 90% so that it looks like the button was pressed playAgainButtonSpriteDown->setScale(0.9f); CCMenuItemSprite *playAgainButton = CCMenuItemSprite::create(playAgainButtonSpriteUp, playAgainButtonSpriteDown, this, menu_selector(GameOverLayer::playAgainButtonTouched)); playAgainButton->setPositionX(-playAgainButton->getContentSize().width/1.2); playAgainButton->runAction(CCRepeatForever::create(CCSequence::createWithTwoActions(CCScaleTo::create(1.0f, 1.2f), CCScaleTo::create(1.0f, 1.0f)))); // Create the mainButton CCSprite *mainButtonSpriteUp = CCSprite::createWithSpriteFrameName("main_button.png"); CCSprite *mainButtonSpriteDown = CCSprite::createWithSpriteFrameName("main_button.png"); // Scale the down to 90% so that it looks like the button was pressed mainButtonSpriteDown->setScale(0.9f); CCMenuItemSprite *mainButton = CCMenuItemSprite::create(mainButtonSpriteUp, mainButtonSpriteDown, this, menu_selector(GameOverLayer::mainButtonTouched)); mainButton->setPositionX(mainButton->getContentSize().width/1.2); // Create the start game menu CCMenu *gameMenu = CCMenu::create(playAgainButton, mainButton, NULL); // Set the initial position off screen gameMenu->setPosition(ccp(SCREEN_WIDTH/2, -SCREEN_HEIGHT)); // Set the tag of the start menu so that we can refer to it later using getChildByTag(...) gameMenu->setTag(kGameOverLayer_PlayAgainMenu); // Create and run an animation that will slide the start game menu in from below the screen to its intended location CCActionInterval *moveAction = CCMoveTo::create(0.3f, ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.15)); CCFiniteTimeAction *easeIn = CCEaseIn::create(moveAction, 0.2f); gameMenu->runAction(easeIn); // Add the start menu to the layer this->addChild(gameMenu); }
//-------------------------------------------------------------- // // void COption::onEnter() { CCXMLLayer::onEnter(); LoadPlist("option.plist"); const char *MenuButton[] = { "button_back", "button_delsave", }; for( int i = 0; i < 2; i++ ) { CCSprite *pSprite= (CCSprite*)GetXMLNodeFromKey( MenuButton[i] ); CCMenu *pMenu = CreatGameUIWithSprite( pSprite, menu_selector(COption::menuCallback), i, this, pSprite->getPosition() ); addChild( pMenu, pSprite->getZOrder() ); pMenu->setTag( i ); removeChild( pSprite, true ); } const char *MenuButton2[] = { "button_close1", "button_close2", "button_open1", "button_open2" }; for( int i = 0; i < 4; i++ ) { CCSprite *pSprite= (CCSprite*)GetXMLNodeFromKey( MenuButton2[i] ); CCMenu *pMenu = CreatGameUIWithSprite( pSprite, menu_selector(COption::menuSound), i%2, this, pSprite->getPosition() ); addChild( pMenu, pSprite->getZOrder() ); pMenu->setTag( i ); pMenu->setIsVisible( false ); removeChild( pSprite, true ); m_pControlMenu[i] = pMenu; } //CCUserDefault::sharedUserDefault()->setBoolForKey("music", true ); //CCUserDefault::sharedUserDefault()->setBoolForKey("sound", true ); schedule( schedule_selector( COption::UpData ), 0.1f ); }
CCMenuItemImage* HelloWorld::createBlock(int posX, int posY, float sizeY, int tag) { CCMenu* menu = CCMenu::create(); CCMenuItemImage* block = CCMenuItemImage::create("/block.png","/block.png",this,menu_selector(HelloWorld::selectBlock)); block->setScale(float(0.3)); block->setPosition(ccp(posX,posY)); block->setScaleX(sizeY); block->setTag(tag); menu->setTag(tag); menu->addChild(block); this->addChild(menu); return block; }
CCMenuItemImage* HelloWorld::createPillar(int posX, int tag) { CCMenu* menu = CCMenu::create(); CCMenuItemImage* pillar = CCMenuItemImage::create("/pillar.png","/pillar.png",this,menu_selector(HelloWorld::selectPillar)); pillar->setScaleX(float(0.2)); pillar->setScaleY(float(0.4)); pillar->setPosition(ccp(posX,-75)); pillar->setTag(tag); pillar->setEnabled(false); menu->setTag(tag); menu->addChild(pillar); this->addChild(menu); return pillar; }
void StoryWorld::specialPartSwitchCase(int code) { switch (code) { case '1':{ setTouchEnabled(false); CCSprite *back = CCSprite::create(CONFIRM_BACKGROUND_IMG_PATH); back->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/2)); back->setTag(3); addChild(back, 3); CCLabelTTF *nextPlaceName = CCLabelTTF::create("", "Heiti SC", 48); nextPlaceName->setString(dialog+5); nextPlaceName->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 3.1)); back->addChild(nextPlaceName); CCMenuItemImage *confirmBtn = CCMenuItemImage::create(CONFIRM_BUTTOM_IMG_PATH, CONFIRM_BUTTOM_IMG_PATH, this, menu_selector(StoryWorld::confirmButtonHandler)); confirmBtn->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 2)); CCMenu *menu = CCMenu::create(confirmBtn, NULL); menu->setPosition(CCPointZero); menu->setTag(2); addChild(menu, 3); } break; case '2':{ setTouchEnabled(false); CCSprite* staff_bg = CCSprite::create(STAFFBG_IMG_PATH); staff_bg->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2 + CCDirector::sharedDirector()->getVisibleOrigin().x, CCDirector::sharedDirector()->getVisibleSize().height/2 + CCDirector::sharedDirector()->getVisibleOrigin().y)); addChild(staff_bg, 4); CCSprite* staff = CCSprite::create(STAFF_IMG_PATH); staff->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, -CCDirector::sharedDirector()->getVisibleSize().height/2)); addChild(staff, 5); CCActionInterval * moveTo = CCMoveTo::create(10,ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height*3/2)); CCFiniteTimeAction* sequneceAction = CCSequence::create(moveTo, CCCallFunc::create(this, callfunc_selector(StoryWorld::gameOverAndBackToWelcome)), NULL); staff->runAction(sequneceAction); } break; case '3':{ CCSprite *black = CCSprite::create(BLACK_IMG_PATH); black->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/2)); black->setOpacity(0); addChild(black, 4); black->runAction(CCSequence::create(CCFadeIn::create(0.5), CCFadeOut::create(0.5), NULL)); } break; default: break; } }
void MarketScene::initButton() { CCMenuItemImage *pMenuItem = CCMenuItemImage::create(s_pMenuItemBack.charMapFile, s_pMenuItemBack.charMapFilePress, this, menu_selector(MarketScene::buttonCallback)); if (NULL != pMenuItem) { pMenuItem->setAnchorPoint(ccp(1,1)); pMenuItem->setPosition(SCREEN); pMenuItem->setTag(BTN_CLOSE); } CCMenu *pMenu = CCMenu::create(pMenuItem, NULL); if (NULL != pMenu) { pMenu->setPosition(CCPointZero); addChild(pMenu); pMenu->setTag(TAG_MENU); } pMenuItem = CCMenuItemImage::create(s_pMenuItemBuy.charMapFile, s_pMenuItemBuy.charMapFilePress, s_pBuyDisable, this, menu_selector(MarketScene::buttonCallback)); pMenuItem->setAnchorPoint(ccp(0.5f, 0.5f)); pMenuItem->setPosition(ccp(CENTER.x, 120)); pMenuItem->setTag(BTN_BUY); pMenu->addChild(pMenuItem); char szFileName[32] = { 0 }; char szFileName2[32] = { 0 }; char szFileName3[32] = { 0 }; for (int i = 0; i < CARD_COUNT; i++) { sprintf(szFileName, s_pathCard.charMapFile, i); sprintf(szFileName2, s_pathCard.charMapFilePress, i); sprintf(szFileName3, s_pathCardDisable, i); CCMenuItemImage *pItem0 = CCMenuItemImage::create(szFileName, szFileName2, szFileName3); CCMenuItemImage *pItem1 = CCMenuItemImage::create(szFileName2, szFileName); CCMenuItemToggle *pToggle = CCMenuItemToggle::createWithTarget(this, menu_selector(MarketScene::buttonCallback), pItem0, pItem1, NULL); pToggle->setPosition(ccp(120 * i + s_pathCard.m_Position.x, s_pathCard.m_Position.y)); pToggle->setTag(BTN_CARD + i); if (g_Control.cards[i] > 0) { CCSprite *sprite = CCSprite::create(s_pathCardbuy.m_strPath); sprite->setPosition(s_pathCardbuy.m_Position); pToggle->addChild(sprite, TAG_CARD_BUY, TAG_CARD_BUY); } pMenu->addChild(pToggle); } checkCard(BTN_CARD); }
void MainGameScene::makeRetryButton() { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCMenuItemImage* retryItem = CCMenuItemImage::create("menu_waku.png","menu_waku.png" ,this, menu_selector(MainGameScene::showResumeDialog)); retryItem->setScale(0.5); CCSize pRetryItemSize = retryItem->getContentSize(); retryItem->setPosition(ccp( pRetryItemSize.width * 0.4, winSize.height - pRetryItemSize.height * 0.4)); CCMenu* retryButton = CCMenu::create(retryItem,NULL); retryButton->setPosition(CCPointZero); retryButton->setTag(tagRetryButton); retryButton->setEnabled(false); this->addChild(retryButton); }
bool RPGMapItemsMenuLayer::init(cocos2d::CCDictionary *stringList, CppSQLite3DB *db, float width, float height) { if(CCLayerColor::initWithColor(ccc4(0, 0, 0, 200), width, height)) { this->m_stringList = stringList; this->m_stringList->retain(); this->m_db = db; this->m_itemsList = new CCArray(); this->m_itemsList->init(); CCTMXTiledMap *mainBg = CCTMXTiledMap::create(CCString::createWithFormat("map_menu3_%s.tmx", CCUserDefault::sharedUserDefault()->getStringForKey(GAME_STYLE).c_str())->getCString()); mainBg->setPosition(CCPointZero); mainBg->setTag(kRPGMapItemsMenuLayerTagBg); this->addChild(mainBg); CCMenu *mainMenu = CCMenu::create(); mainMenu->setTag(kRPGMapItemsMenuLayerTagMainMenu); mainMenu->setAnchorPoint(CCPointZero); mainMenu->setPosition(CCPointZero); this->addChild(mainMenu); CCMenuItemSprite *menuBack = (CCMenuItemSprite*)mainMenu->getChildByTag(kRPGMapItemsMenuLayerTagMainMenuBack); if(!menuBack) { menuBack = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGMapItemsMenuLayer::onMenu)); menuBack->setPosition(ccp(40, 600)); menuBack->setTag(kRPGMapItemsMenuLayerTagMainMenuBack); menuBack->setScale(0.5); mainMenu->addChild(menuBack); } CCTableView *tableView = CCTableView::create(this, CCSizeMake(900, 570)); tableView->setDirection(kCCScrollViewDirectionVertical); tableView->setPosition(ccp(80, 30)); tableView->setDelegate(this); tableView->setVerticalFillOrder(kCCTableViewFillTopDown); tableView->setTag(kRPGMapItemsMenuLayerTagItemListTable); this->addChild(tableView); this->loadItemsData(); return true; } return false; }
void MainGameScene::makeClearDaialog() { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCMenuItemImage* titleItem = CCMenuItemImage::create("logo_menu.png","logo_menu.png" ,this, menu_selector(MainGameScene::tapTitleButton)); titleItem->setPosition(ccp(winSize.width * 0.3, winSize.height * 0.3)); CCMenuItemImage* retryItem = CCMenuItemImage::create("logo_restart.png","logo_restart.png" ,this, menu_selector(MainGameScene::tapRetryButton)); retryItem->setPosition(ccp(winSize.width * 0.8, winSize.height * 0.3)); CCMenu* clearDialog = CCMenu::create(titleItem,retryItem,NULL); clearDialog->setPosition(CCPointZero); clearDialog->setTag(tagClearDialog); clearDialog->setOpacity(0); clearDialog->setEnabled(false); this->addChild(clearDialog); }
//private void RPGDialogLayer::initCommons(string titleStr) { CCTMXTiledMap *mainBg = CCTMXTiledMap::create("alert_style1.tmx"); float x = (CCDirector::sharedDirector()->getWinSize().width - mainBg->getContentSize().width) / 2.0f; float y = (CCDirector::sharedDirector()->getWinSize().height - mainBg->getContentSize().height) / 2.0f; mainBg->setPosition(ccp(x, y)); mainBg->setTag(kRPGDialogLayerBg); this->addChild(mainBg); CCLabelTTF *titleLab = CCLabelTTF::create(titleStr.c_str(), "Arial", 25, CCSizeMake(mainBg->getContentSize().width, 25), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter); titleLab->setPosition(ccp(190, 135)); titleLab->setColor(ccc3(255, 255, 255)); mainBg->addChild(titleLab); CCMenu *menu = CCMenu::create(); menu->setAnchorPoint(CCPointZero); menu->setPosition(CCPointZero); menu->setTag(kRPGDialogLayerBgMenu); mainBg->addChild(menu); }
void MainGameScene::showStartInfo() { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCMenuItemImage* pStartItem; pStartItem = CCMenuItemImage::create("logo_Info2.png", "logo_Info2.png",this,menu_selector(MainGameScene::startGame)); pStartItem->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.5)); pStartItem->setScale(0.7); CCSize pStartItemSize = pStartItem->getContentSize(); CCLabelTTF* startLabel1; startLabel1 = CCLabelTTF::create("Let's Arrows", "Copperplate", 60.0); startLabel1->setColor(ccc3(0, 0, 0)); startLabel1->setPosition(ccp(pStartItemSize.width * 0.5 ,pStartItemSize.height * 0.7)); pStartItem->addChild(startLabel1); CCString* levelStr = CCString::createWithFormat("Lv:%d",m_level); CCLabelTTF* levelLabel; levelLabel = CCLabelTTF::create(levelStr->getCString(), "Copperplate", 60.0); levelLabel->setColor(ccc3(0, 0, 0)); levelLabel->setPosition(ccp(pStartItemSize.width * 0.5 ,pStartItemSize.height * 0.5)); pStartItem->addChild(levelLabel); CCString* minCountString = CCString::createWithFormat("MIN %d TOUCH",minimamCount); CCLabelTTF* startLabel2; startLabel2 = CCLabelTTF::create(minCountString->getCString(), "Copperplate", 50.0); startLabel2->setColor(ccc3(0, 0, 0)); startLabel2->setPosition(ccp(pStartItemSize.width * 0.5 ,pStartItemSize.height * 0.2)); pStartItem->addChild(startLabel2); CCMenu* pMenu = CCMenu::create(pStartItem,NULL); pMenu->setPosition(CCPointZero); pMenu->setTag(tagStartInfo); this->addChild(pMenu); }
void MenuScene::freeToGetFubi() { //添加免费领取富币的背景,非0为第一次登录,测试显示,0为第一次登录 CCLog("-------MenuScene:您第一次登陆,获得富币--------"); this->setMenuButtonTouchFasle(); //背景框 CCSprite *acceptFreeFubiImage = CCSprite::create("ZF_Shoot_MenuScene_background_freeFubi.png"); acceptFreeFubiImage->setPosition(CCPointMake(size.width/2, size.height/2)); acceptFreeFubiImage->setTag(111); this->addChild(acceptFreeFubiImage, 1,111); //确认或者拒绝 CCMenuItemImage *yes = CCMenuItemImage::create("ZF_Shoot_MenuScene_background_freeFubi_confirm1.png", "ZF_Shoot_MenuScene_background_freeFubi_confirm1.png", this, menu_selector(MenuScene::menuCallAcceptFubiYes)); yes->setContentSize(CCSizeMake(200, 100)); yes->setPosition(CCPointMake(acceptFreeFubiImage->getContentSize().width/2+50, acceptFreeFubiImage->getContentSize().height*0.4)); CCMenu *menu = CCMenu::create(yes,NULL); menu->setPosition(CCPointZero); menu->setTag(112); acceptFreeFubiImage->addChild(menu, 1,112); }
bool GameSprite_Rice::init() { if (!CCSprite::init()) { return false; } this->setContentSize(CCSize(500, 70)); addRiceTime = RICEADDTIME; riceNum = 0; nowTime = 0; nowTime = this->getCurrentTime(); //字体背景. CCMenuItemImage *labelBgSprite = CCMenuItemImage::create(); labelBgSprite->setNormalSpriteFrame(GameShare_Texture::sharedTexture()->GetSpriteFrameByCCRect(akoomenu_image, CCRect(1763, 255, 120, 49))); labelBgSprite->setAnchorPoint(CCPointZero); labelBgSprite->setPosition(CCPointZero); labelBgSprite->setTag(Key_Add); CCMenu* pMenu = CCMenu::create(labelBgSprite, NULL); pMenu->setPosition(ccp(300,0)); pMenu->setTag(Key_Add); this->addChild(pMenu); //时间标签. CCLabelTTF *timeLabel = CCLabelTTF::create("", "Arial", 20); ccColor3B color = ccc3(95, 46, 33); char strTime[32]; sprintf(strTime,"%d:%d%d",addRiceTime/60,addRiceTime%60/10,addRiceTime%60%10); timeLabel->setColor(color); timeLabel->setString(strTime); timeLabel->setTag(Key_Time); timeLabel->setPosition(ccp(pMenu->getPositionX()+40, pMenu->getPositionY()+20)); this->addChild(timeLabel); //饭的背景 CCSprite *riceBgSprite = GameShare_Texture::sharedTexture()->GetSpriteByCCRect(akoomenu_image, CCRect(1, 1570, 278, 30)); riceBgSprite->setAnchorPoint(CCPointZero); riceBgSprite->setPosition(ccp(0,5)); this->addChild(riceBgSprite); this->schedule(schedule_selector(GameSprite_Rice::timeUpdate), 1.0); return true; }
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; }
void FSAlertLayer::setStyle(const char* message, CCObject *target, SEL_CallFuncN okSelector, SEL_CallFuncN ngSelector) { this->target = target; this->okSelector = okSelector; this->ngSelector = ngSelector; CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); // Label CCLabelTTF *pMsg = CCLabelTTF::create(message, "", 40); pMsg->setPosition(ccp(visibleSize.width / 2, visibleSize.height / 2 + 50)); pMsg->setColor(ccc3(0,0,0)); this->addChild(pMsg); // OK Button CCMenuItemImage *pOKItem = CCMenuItemImage::create("send_mail_btm.png", "send_mail_btm.png", this, menu_selector(FSAlertLayer::menuAlertOK)); int btnHeight = visibleSize.height / 2 - this->getChildByTag(FSAlertLayerTagFrame)->getContentSize().height / 2 + pOKItem->getContentSize().height / 2 + 10; pOKItem->setTag(FSAlertLayerTagOK); pOKItem->setPosition(ccp(visibleSize.width / 2 , btnHeight +10)); CCMenu* pMenu = CCMenu::create(pOKItem, NULL); pMenu->setPosition(CCPointZero); pMenu->setTag(FSAlertLayerTagMenu); this->addChild(pMenu); // Set Cancel button if (ngSelector) { CCMenuItemImage* pNGItem = CCMenuItemImage::create("close_btn.png", "close_btn.png", this, menu_selector(FSAlertLayer::menuAlertClose)); pNGItem->setTag(FSAlertLayerTagNG); int cancelWidth = visibleSize.width/2 + this->getChildByTag(FSAlertLayerTagFrame)->getContentSize().width/2; int cancelHeight = visibleSize.height/2 + this->getChildByTag(FSAlertLayerTagFrame)->getContentSize().height/2; //pNGItem->setPosition(ccp(visibleSize.width / 2 + pOKItem->getContentSize().width, btnHeight +10)); CCLog("cancelPosition ===> %i",cancelWidth); CCLog("cancelPosition ===> %i",cancelHeight); pNGItem->setPosition(ccp(cancelWidth,cancelHeight)); pMenu->addChild(pNGItem); } }
void FSAlertLayer::setStyle(const char* message, cocos2d::CCObject *target, cocos2d::SEL_CallFuncN okSelector, cocos2d::SEL_CallFuncN ngSelector) { this->target = target; this->okSelector = okSelector; this->ngSelector = ngSelector; CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); // message CCLabelTTF *pMsg = CCLabelTTF::create(message, "", 42); pMsg->setPosition(ccp(visibleSize.width / 2 +100, visibleSize.height/2+36)); this->addChild(pMsg); // OK Button CCMenuItemImage *pNGItem = CCMenuItemImage::create("images/retray_button_cancel.png", "images/retray_button_canel.png", this, menu_selector(FSAlertLayer::menuAlertClose)); int btnHeight = visibleSize.height / 2 - this->getChildByTag(FSAlertLayerTagFrame)->getContentSize().height / 2 + pNGItem->getContentSize().height / 2 + 10; pNGItem->setTag(FSAlertLayerTagNG); pNGItem->setPosition(ccp(visibleSize.width / 2, btnHeight)); CCMenu* pMenu = CCMenu::create(pNGItem, NULL); pMenu->setPosition(CCPointZero); pMenu->setTag(FSAlertLayerTagMenu); this->addChild(pMenu); // set as 2 buttons if (okSelector) { pNGItem->setPosition(ccp(visibleSize.width / 2 - pNGItem->getContentSize().width / 2-10, btnHeight +10)); // NG btn CCMenuItemImage* pOKItem = CCMenuItemImage::create("images/retray_button_ok.png", "images/retray_button_ok.png", this, menu_selector(FSAlertLayer::menuAlertOK)); pOKItem->setTag(FSAlertLayerTagOK); pOKItem->setPosition(ccp(visibleSize.width / 2 + pOKItem->getContentSize().width / 2+10, btnHeight +10)); pMenu->addChild(pOKItem); } }
bool CCStoreScene::init(void) { CCScene::init(); const char* contents = "CHANGE CCStoreScene::testLoadProducts(),\nSET YOUR IAP PRODUCT ID"; const CCSize& winSize = CCDirector::sharedDirector()->getWinSize(); CCLabelTTF* label = CCLabelTTF::labelWithString(contents, CCSize(winSize.width, 0), CCTextAlignmentCenter, "Arial", 18); label->setPosition(ccp(winSize.width / 2, winSize.height - 60)); addChild(label); label = CCLabelTTF::labelWithString("loadProducts()", "Arial", 22); CCMenuItemLabel* item1 = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(CCStoreScene::testLoadProducts)); label = CCLabelTTF::labelWithString("purchase()", "Arial", 22); CCMenuItemLabel* item2 = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(CCStoreScene::testPurchase)); label = CCLabelTTF::labelWithString("- BACK -", "Arial", 22); CCMenuItemLabel* itemBack = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(CCStoreScene::backToMainScene)); CCMenu* pMenu = CCMenu::menuWithItems(item1, item2, itemBack, NULL); pMenu->alignItemsVertically(); pMenu->setTag(MENU_TAG); addChild(pMenu); CCStore::sharedStore()->postInitWithTransactionObserver(this); CCStore::sharedStore()->setReceiptVerifyMode(CCStoreReceiptVerifyModeDevice); return true; }
//------------------------------------------------------------------ // // MenuLayer2 // //------------------------------------------------------------------ MenuLayer2::MenuLayer2() { for( int i=0;i < 2;i++ ) { CCMenuItemImage* item1 = CCMenuItemImage::itemFromNormalImage(s_PlayNormal, s_PlaySelect, this, menu_selector(MenuLayer2::menuCallback)); CCMenuItemImage* item2 = CCMenuItemImage::itemFromNormalImage(s_HighNormal, s_HighSelect, this, menu_selector(MenuLayer2::menuCallbackOpacity) ); CCMenuItemImage* item3 = CCMenuItemImage::itemFromNormalImage(s_AboutNormal, s_AboutSelect, this, menu_selector(MenuLayer2::menuCallbackAlign) ); item1->setScaleX( 1.5f ); item2->setScaleX( 0.5f ); item3->setScaleX( 0.5f ); CCMenu* menu = CCMenu::menuWithItems(item1, item2, item3, NULL); menu->setTag( kTagMenu ); addChild(menu, 0, 100+i); m_centeredMenu = menu->getPosition(); } m_alignedH = true; alignMenusH(); }
//private void RPGMapSceneLayer::startPlay(float delay) { CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap); //数据库部分,读取npc数据 CppSQLite3Query query = this->m_db.execQuery(CCString::createWithFormat(NPC_QUERY, this->m_mapData.mapId)->getCString()); while(!query.eof()) { float x = (stringToNumber<float>(query.getStringField("tmx_x")) + 0.5) * GAME_TMX_ROLE_WIDTH; float y = (stringToNumber<float>(query.getStringField("tmx_y")) + 0.5) * GAME_TMX_ROLE_HEIGHT; bool autoMove = query.getIntField("auto_move") == 1 ? true : false; RPGMapNPCRoleSprite *npc = RPGMapNPCRoleSprite::create(query.getIntField("id"), CCString::create(query.getStringField("map_texture")), CCString::create("head_texture"), CCString::create(query.getStringField("name_cns")), CCString::create(query.getStringField("content_cns")), 1, autoMove); npc->setTag(kRPGMapSceneLayerTagNPC + query.getIntField("id")); npc->setPosition(ccp(x, y)); bgMap->addChild(npc); query.nextRow(); } query.finalize(); //player int defaultSpriteFrameIndex = 1; //默认为向下 if(this->m_mapData.playerDirection.compare("up") == 0) { defaultSpriteFrameIndex = 10; } else if(this->m_mapData.playerDirection.compare("left") == 0) { defaultSpriteFrameIndex = 4; } else if(this->m_mapData.playerDirection.compare("right") == 0) { defaultSpriteFrameIndex = 7; } RPGMapRoleSprite *player = RPGMapRoleSprite::create(CCString::create("actor4_0.png"), CCString::create("Player"), true, defaultSpriteFrameIndex); player->setPosition(ccp(this->m_mapData.playerToX * GAME_TMX_ROLE_WIDTH, this->m_mapData.playerToY * GAME_TMX_ROLE_HEIGHT)); player->setTag(kRPGMapSceneLayerTagPlayer); player->m_type = kRPGMapRoleSpriteTypePlayer; bgMap->addChild(player); CCSprite *spJoystick = CCSprite::createWithSpriteFrameName("Ball.png"); CCSprite *joystickBg = CCSprite::createWithSpriteFrameName("Dock.png"); OzgJoystickLayer *joystick = OzgJoystickLayer::layerActivityJoystick(50, spJoystick, joystickBg, false); joystick->setTag(kRPGMapSceneLayerTagJoystick); joystick->m_target = this; joystick->m_endedSelector = callfunc_selector(RPGMapSceneLayer::joystickEndedFunc); this->addChild(joystick); //menu CCMenu *mainMenu = CCMenu::create(); mainMenu->setTag(kRPGMapSceneLayerTagMainMenu); mainMenu->setAnchorPoint(ccp(0.5, 0.5)); mainMenu->setPosition(CCPointZero); mainMenu->setContentSize(bgMap->getContentSize()); bgMap->addChild(mainMenu); CCMenuItemSprite *menuCommand = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGMapSceneLayer::onMenu)); menuCommand->setPosition(ccp(mainMenu->getContentSize().width - 35, mainMenu->getContentSize().height - 35)); menuCommand->setTag(kRPGMapSceneLayerTagMainMenuCommand); menuCommand->setRotation(180); menuCommand->setScale(0.75); mainMenu->addChild(menuCommand); // CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo(); CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 1, true); this->scheduleUpdate(); }
bool LevelGame05::init() { if ( !CCLayer::init() ) { return false; } //isNext = false; flagMusic = false; CCUserDefault::sharedUserDefault()->setIntegerForKey("level_5", 1); CCUserDefault::sharedUserDefault()->flush(); count=9; isDouble=false; isMatch=false; lastItemIndex=0;//1-9 curItemIndex=0;//1-9 isFinish=true; isKillSchedule=false; CCSize size = CCDirector::sharedDirector()->getWinSize(); CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile("level-5.plist"); CCSprite* sprite =CCSprite::createWithSpriteFrameName("background-5.png"); CCSize sprite_size = sprite->getContentSize(); sprite->setScaleX(size.width/sprite_size.width); sprite->setScaleY(size.height/sprite_size.height); sprite->setPosition(CCPoint(size.width*0.5,size.height*0.5)); sprite->setTag(90); this->addChild(sprite); CCMenuItemImage *pItem1 = CCMenuItemImage::create(); pItem1->setNormalSpriteFrame(cache->spriteFrameByName("poker.png")); pItem1->setSelectedSpriteFrame(cache->spriteFrameByName("poker.png")); pItem1->initWithTarget(this,menu_selector(LevelGame05::ItemCallback1)); pItem1->setPosition(ccp(size.width*0.5, size.height*0.5+200)); pItem1->setTag(91); CCMenuItemImage *pItem2 = CCMenuItemImage::create(); pItem2->setNormalSpriteFrame(cache->spriteFrameByName("poker.png")); pItem2->setSelectedSpriteFrame(cache->spriteFrameByName("poker.png")); pItem2->initWithTarget(this,menu_selector(LevelGame05::ItemCallback2)); pItem2->setPosition(ccp(size.width*0.5+200, size.height*0.5+200)); pItem2->setTag(92); CCMenuItemImage *pItem3 = CCMenuItemImage::create(); pItem3->setNormalSpriteFrame(cache->spriteFrameByName("poker.png")); pItem3->setSelectedSpriteFrame(cache->spriteFrameByName("poker.png")); pItem3->initWithTarget(this,menu_selector(LevelGame05::ItemCallback3)); pItem3->setPosition(ccp(size.width*0.5+400, size.height*0.5+200)); pItem3->setTag(93); CCMenuItemImage *pItem4 = CCMenuItemImage::create(); pItem4->setNormalSpriteFrame(cache->spriteFrameByName("poker.png")); pItem4->setSelectedSpriteFrame(cache->spriteFrameByName("poker.png")); pItem4->initWithTarget(this,menu_selector(LevelGame05::ItemCallback4)); pItem4->setPosition(ccp(size.width*0.5, size.height*0.5)); pItem4->setTag(94); CCMenuItemImage *pItem5 = CCMenuItemImage::create(); pItem5->setNormalSpriteFrame(cache->spriteFrameByName("poker.png")); pItem5->setSelectedSpriteFrame(cache->spriteFrameByName("poker.png")); pItem5->initWithTarget(this,menu_selector(LevelGame05::ItemCallback5)); pItem5->setPosition(ccp(size.width*0.5+200, size.height*0.5)); pItem5->setTag(95); CCMenuItemImage *pItem6 = CCMenuItemImage::create(); pItem6->setNormalSpriteFrame(cache->spriteFrameByName("poker.png")); pItem6->setSelectedSpriteFrame(cache->spriteFrameByName("poker.png")); pItem6->initWithTarget(this,menu_selector(LevelGame05::ItemCallback6)); pItem6->setPosition(ccp(size.width*0.5+400, size.height*0.5)); pItem6->setTag(96); CCMenuItemImage *pItem7 = CCMenuItemImage::create(); pItem7->setNormalSpriteFrame(cache->spriteFrameByName("poker.png")); pItem7->setSelectedSpriteFrame(cache->spriteFrameByName("poker.png")); pItem7->initWithTarget(this,menu_selector(LevelGame05::ItemCallback7)); pItem7->setPosition(ccp(size.width*0.5, size.height*0.5-200)); pItem7->setTag(97); CCMenuItemImage *pItem8 = CCMenuItemImage::create(); pItem8->setNormalSpriteFrame(cache->spriteFrameByName("poker.png")); pItem8->setSelectedSpriteFrame(cache->spriteFrameByName("poker.png")); pItem8->initWithTarget(this,menu_selector(LevelGame05::ItemCallback8)); pItem8->setPosition(ccp(size.width*0.5+200, size.height*0.5-200)); pItem8->setTag(98); CCMenuItemImage *pItem9 = CCMenuItemImage::create(); pItem9->setNormalSpriteFrame(cache->spriteFrameByName("poker.png")); pItem9->setSelectedSpriteFrame(cache->spriteFrameByName("poker.png")); pItem9->initWithTarget(this,menu_selector(LevelGame05::ItemCallback9)); pItem9->setPosition(ccp(size.width*0.5+400, size.height*0.5-200)); pItem9->setTag(99); CCMenu* pmenu= CCMenu::create(pItem1,pItem2,pItem3,pItem4,pItem5, pItem6,pItem7,pItem8,pItem9,NULL); pmenu->setPosition(CCPointZero); pmenu->setTag(100); //pmenu->setEnabled(false); this->addChild(pmenu); CCMenuItemImage *pauseItem = CCMenuItemImage::create(); pauseItem->setNormalSpriteFrame(cache->spriteFrameByName("pause-1.png")); pauseItem->setSelectedSpriteFrame(cache->spriteFrameByName("pause-2.png")); pauseItem->initWithTarget(this, menu_selector(LevelGame05::pauseCallback)); pauseItem->setPosition(CCPoint(size.width-100,size.height*0.9)); CCMenu *pauseMenu = CCMenu::create(pauseItem, NULL); pauseMenu->setPosition(CCPointZero); pauseMenu->setTag(101); this->addChild(pauseMenu, 1); if(isMusic == true) { SimpleAudioEngine::sharedEngine()->playBackgroundMusic("back2.mp3",true); flagMusic = true; } return true; }
bool LevelGame04::init() { if ( !CCLayer::init() ) { return false; } isFailed = false; flagMusic = false; isMenu=0; //cocos2d-x3.0中的点击事件 //auto dispatcher = Director::getInstance()->getEventDispatcher(); //auto touchListener = EventListenerTouchOneByOne::create(); //touchListener->onTouchBegan = CC_CALLBACK_2(HistoryGame02::onTouchBegan, this); //dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); CCUserDefault::sharedUserDefault()->setIntegerForKey("level_4", 1); CCUserDefault::sharedUserDefault()->flush(); //加入背景 CCSize size = CCDirector::sharedDirector()->getWinSize(); CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile("level-4.plist"); CCSprite* sprite =CCSprite::createWithSpriteFrameName("background-4.png"); CCSize sprite_size = sprite->getContentSize(); sprite->setScaleX(size.width/sprite_size.width); sprite->setScaleY(size.height/sprite_size.height); sprite->setPosition(CCPoint(size.width*0.5,size.height*0.5)); sprite->setTag(98); this->addChild(sprite); //ClickME图标 CCMenuItemImage *clickmeItem = CCMenuItemImage::create(); clickmeItem->setNormalSpriteFrame(cache->spriteFrameByName("clickme_1.png")); clickmeItem->setSelectedSpriteFrame(cache->spriteFrameByName("clickme_2.png")); clickmeItem->initWithTarget(this,menu_selector(LevelGame04::clickmeCallback)); clickmeItem->setPosition(ccp(size.width / 2 , size.height / 2)); CCMenu* pmenu= CCMenu::create(clickmeItem, NULL); pmenu->setPosition(CCPointZero); pmenu->setTag(100); //pmenu->setEnabled(false); this->addChild(pmenu); //ME和NU两个图标 CCMenuItemImage *meItem = CCMenuItemImage::create(); meItem->setNormalSpriteFrame(cache->spriteFrameByName("ME.png")); meItem->setSelectedSpriteFrame(cache->spriteFrameByName("ME.png")); meItem->initWithTarget(this,menu_selector(LevelGame04::meCallback)); meItem->setPosition(ccp(100, size.height*0.9)); meItem->setTag(101); CCMenu* meMenu= CCMenu::create(meItem, NULL); meMenu->setPosition(CCPointZero); meMenu->setTag(103); this->addChild(meMenu,1); CCMenuItemImage *nuItem = CCMenuItemImage::create(); nuItem->setNormalSpriteFrame(cache->spriteFrameByName("NU.png")); nuItem->setSelectedSpriteFrame(cache->spriteFrameByName("NU.png")); //yiItem->initWithTarget(this,menu_selector(LevelGame01::yiCallback)); nuItem->setPosition(ccp(184, size.height*0.9)); CCMenu* nuMenu= CCMenu::create(nuItem, NULL); nuMenu->setPosition(CCPointZero); nuMenu->setTag(102); this->addChild(nuMenu,1); // cache->addSpriteFramesWithFile("UIResoure.plist"); //batch = CCSpriteBatchNode::create("UIResoure.png"); //this->addChild(batch); CCMenuItemImage *pauseItem = CCMenuItemImage::create(); pauseItem->setNormalSpriteFrame(cache->spriteFrameByName("pause-1.png")); pauseItem->setSelectedSpriteFrame(cache->spriteFrameByName("pause-2.png")); pauseItem->initWithTarget(this, menu_selector(LevelGame04::pauseCallback)); pauseItem->setPosition(CCPoint(size.width-100,size.height*0.9)); CCMenu *pauseMenu = CCMenu::create(pauseItem, NULL); pauseMenu->setPosition(CCPointZero); pauseMenu->setTag(104); this->addChild(pauseMenu, 1); if(isMusic == true) { SimpleAudioEngine::sharedEngine()->playBackgroundMusic("back2.mp3",true); flagMusic = true; } return true; }
CCTableViewCell* RequestList::tableCellAtIndex(CCTableView *table, unsigned int idx) { int index = idx; EziFBIncomingRequest* fbRequest = (EziFBIncomingRequest*)_fbIncomingRequestList->objectAtIndex(index); EziFacebookFriend* sender = fbRequest->getSender(); const char* senderName = sender->getName(); // Create the fancy test. EziSocialWrapperNS::FB_REQUEST::TYPE requestType = fbRequest->getRequestType(); std::string messageToDisplay = ""; switch (requestType) { case EziSocialWrapperNS::FB_REQUEST::REQUEST_INVITE: messageToDisplay.append(senderName).append(" has sent invitation to you."); break; case EziSocialWrapperNS::FB_REQUEST::REQUEST_GIFT: messageToDisplay.append(senderName).append(" has sent gift to you."); break; case EziSocialWrapperNS::FB_REQUEST::REQUEST_CHALLENGE: messageToDisplay.append(senderName).append(" has challenged to you."); break; default: messageToDisplay.append("Unknown message"); break; } // Means users have already used this request. bool requestConsumed = fbRequest->isConsumed(); CCSprite* profilePic = NULL; ccColor4B bgColor = ccc4(20, 0, 40, 255); if (requestConsumed == false) { bgColor = ccc4(50, 50, 20, 255); } // Build the table cell. CCTableViewCell *cell = table->dequeueCell(); if (cell == NULL) { cell = new CCTableViewCell(); cell->autorelease(); // Create the back layer of the cell. CCLayerColor* colorLayer = CCLayerColor::create(bgColor, SCREEN_WIDTH, CELL_HEIGHT); colorLayer->setTag(BACKGROUND_TAG); cell->addChild(colorLayer); // Get the sender profile picture path. Create it if path is available. if (sender != NULL && strcmp(sender->getPhotoPath(), "") != 0) { const char* picPath = sender->getPhotoPath(); profilePic = CCSprite::create(picPath); } else { profilePic = CCSprite::create(FB_DEFAULT_PHOTO); } // Add the profile pic to the cell row. profilePic->setAnchorPoint(ccp(0, 0.5)); profilePic->setPosition(ccp(20, CELL_HEIGHT/2)); cell->addChild(profilePic); profilePic->setTag(FRIEND_PHOTO_TAG); // Set the message. CCLabelTTF *messageLabel = CCLabelTTF::create(messageToDisplay.c_str(), "Helvetica", 20.0 * MENU_FONT_SCALE); messageLabel->setAnchorPoint(ccp(0, 0.5)); messageLabel->setPosition(ccp(20 + 20 + profilePic->getContentSize().width, CELL_HEIGHT/2)); messageLabel->setTag(REQUEST_MESSAGE_LABEL_TAG); messageLabel->setDimensions(CCSizeMake(SCREEN_WIDTH - (profilePic->getContentSize().width * 2) - 60, CELL_HEIGHT-5)); messageLabel->setHorizontalAlignment(kCCTextAlignmentLeft); cell->addChild(messageLabel); CCMenuItemImage* constumeItemButton = NULL; constumeItemButton = CCMenuItemImage::create("use.png", "use_pressed.png"); constumeItemButton->setTag(idx); constumeItemButton->setTarget(this, menu_selector(RequestList::useItem)); constumeItemButton->setScale(SCALE_FACTOR * 0.8); constumeItemButton->setTag(FRIEND_CONSUME_BUTTON_TAG); CCMenu* consumeMenu = CCMenu::create(constumeItemButton, NULL); consumeMenu->setTag(FRIEND_CONSUME_MENU_TAG); consumeMenu->setPosition(ccp(SCREEN_WIDTH - (constumeItemButton->getContentSize().width*SCALE_FACTOR*0.4), (CELL_HEIGHT - (constumeItemButton->getContentSize().height)*SCALE_FACTOR*0.4))); cell->addChild(consumeMenu); } else { // Refresh the cell data based upon idx. // 1. Refresh the profile picture. CCSprite* cellProfilePic = (CCSprite*)cell->getChildByTag(FRIEND_PHOTO_TAG); if (strcmp("", sender->getPhotoPath()) != 0 ) { const char* picPath = sender->getPhotoPath(); profilePic = CCSprite::create(picPath); } else { profilePic = CCSprite::create(FB_DEFAULT_PHOTO); } cellProfilePic->setTexture(profilePic->getTexture()); // Update the message Label. CCLabelTTF *messageLabel = (CCLabelTTF*)cell->getChildByTag(REQUEST_MESSAGE_LABEL_TAG); messageLabel->setString(messageToDisplay.c_str()); CCMenu* consumeMenu = (CCMenu*)cell->getChildByTag(FRIEND_CONSUME_MENU_TAG); CCArray* children = consumeMenu->getChildren(); if (children) { CCMenuItemImage* consumenButton = (CCMenuItemImage*)children->objectAtIndex(0); if (consumenButton) { consumenButton->setTag(index); } else { CCLOG("No Consume Button"); } } CCLayerColor* bgLayer = (CCLayerColor*)cell->getChildByTag(BACKGROUND_TAG); bgLayer->setColor(ccc3(bgColor.r, bgColor.g, bgColor.b)); } return cell; }
bool XieziLayer::init() { if ( !CCLayer::init() ) { return false; } CCMenu* pMenu = CCMenu::create(); pMenu->setPosition( CCPointZero ); pMenu->setTag(kTagMenu); this->addChild(pMenu, 1); //小背景 CCSprite* pXbj = CCSprite::createWithSpriteFrameName("dakuang.png"); pXbj->setPosition(S_RM->getPositionWithName("xiezi_xbj")); pXbj->setTag(kTagXBJ); this->addChild(pXbj); UserBarLayer* userBarLayer=S_LM->getDelegate(); if (userBarLayer==NULL) { userBarLayer=UserBarLayer::create(); userBarLayer->setPosition(S_RM->getPositionWithName("xiezi_userbar")); this->addChild(userBarLayer,ORDER_USERBAR); } if (m_isShowX) { CCSprite* x=CCSprite::create("cha.png"); x->setScale(1.5); x->setPosition(S_RM->getPositionWithName("tupian_close")); this->addChild(x); } const char* str; const char* pic; if (m_hanzi->getwriteCount()>0) { str=CCString::createWithFormat("%d",m_hanzi->getwriteCount())->getCString(); pic="xingxing_2.png"; }else{ str=""; pic="xingxing_1.png"; } m_xingxing=CCSprite::createWithSpriteFrameName(pic); m_xingxing->setPosition(S_RM->getPositionWithName("xiezi_xingxing")); this->addChild(m_xingxing); m_count=CCLabelTTF::create(str, "", 30); m_count->setPosition(S_RM->getPositionWithName("xiezi_xingxing")); m_count->setColor(ccc3(0, 0, 0)); this->addChild(m_count); //修改上次进入汉字(用于首页) S_UD->setIntegerForKey(LAST_HANZI_ID, m_hanzi->getid()); S_UD->flush(); m_writedHanziCount=S_DM->getCount("hanzi","writeCount>0"); time_t time= TimeUtils::getToday0Time(); CLAUSE_INIT; whereClause.push_back(CCString::createWithFormat("hid=%d",m_hanzi->getid())->getCString()); whereClause.push_back(CCString::createWithFormat("createTime>%ld",time)->getCString()); vector<XieziLog*>* logVector=new vector<XieziLog*>(); S_DM->findScrollData(logVector,"id",whereClause, orderbyClause, groupByClause); m_todayXieziCount=logVector->size(); m_collectedCount=0; if (m_hanzi->getisCollected()==0) { m_collectedCount=S_DM->getCount("hanzi","isCollected>0"); if (m_collectedCount>=COLLECT_LIMIT) { GuideDialog* guideDialog=new GuideDialog(); guideDialog->autorelease(); guideDialog->setText("非常抱歉,收藏的卡片数量已经超出了限制,请检查账号状态。"); guideDialog->setMode(kGuideDialogOk); m_gudieDialogLayer=GuideDialogLayer::create(kDialogWithText); m_gudieDialogLayer->setDelegate(this); this->addChild(m_gudieDialogLayer,ORDER_DIALOG); m_gudieDialogLayer->setGuideDialogData(guideDialog); }else{ //收集到汉字 CCString *sql=CCString::createWithFormat("update hanzi set isCollected=1 where id=%d;",m_hanzi->getid()); S_DM->executeSql(sql->getCString()); static_userDefaultIncrement(COLLECT_HANZI_COUNT,18); m_collected=true; } } typedef struct _ResouceStruct { string position; string pic; int tag; int spriteTag; }XieziActionStruct; // 在这里配置每个场景要加载的资源 static XieziActionStruct action[] = { { "xiezi_tansuo", "tansuo.png", kTagTansuo, kTagSpriteTansuo }, { "xiezi_xiangpi", "xiangpi.png", kTagRewrite, kTagSpriteXiangpi }, { "xiezi_guangbo", "guangbo.png", kTagGuangbo, kTagSpriteGuangbo } }; for (int i=0; i<3; i++) { CCPoint point=S_RM->getPositionWithName(action[i].position.c_str()); CCSprite* kuang1=CCSprite::createWithSpriteFrameName("xiaokuang_1.png"); CCSprite* kuang2=CCSprite::createWithSpriteFrameName("xiaokuang_2.png"); CCMenuItemSprite* kuang=CCMenuItemSprite::create(kuang1, kuang2, this, menu_selector(XieziLayer::callWeb)); kuang->setPosition(point); kuang->setTag(action[i].tag); pMenu->addChild(kuang); CCSprite* sprite=CCSprite::createWithSpriteFrameName(action[i].pic.c_str()); sprite->setPosition(ccp(point.x,point.y-3)); sprite->setTag(action[i].spriteTag); this->addChild(sprite,2); } //拼音 CCLabelTTF *pinyinLabel = CCLabelTTF::create(m_hanzi->getpinyinyindiao().c_str(), "Pinyinok.ttf", 30.0); pinyinLabel->setColor(ccc3(255, 255, 255)); pinyinLabel->setPosition(S_RM->getPositionWithName("xiezi_pinyin")); this->addChild(pinyinLabel); //定时3秒提醒 if (m_heimao!=NULL) { this->scheduleOnce(schedule_selector(XieziLayer::dingShiTiXing), 6); } return true; }
bool GameHud::init() { bool ret = false; do { CC_BREAK_IF(!CCLayer::init()); CCSize winsize = CCDirector::sharedDirector()->getWinSize(); CCSprite* background = CCSprite::create("hud.png"); background->setAnchorPoint(CCPointZero); float saclex = winsize.width/background->boundingBox().size.width; background->setScaleX(saclex); this->addChild(background); CCMenuItemSprite * item1 = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("A1_0.png"), CCSprite::createWithSpriteFrameName("A1_0.png"), this, menu_selector(GameHud::soldier1_Select)); item1->setPosition(ccp(10,10)); CCMenuItemSprite * item2 = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("A2_0.png"), CCSprite::createWithSpriteFrameName("A2_0.png"), this, menu_selector(GameHud::soldier2_Select)); item2->setPosition(ccp(110, 10)); CCMenuItemSprite * item3 = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("A3_0.png"), CCSprite::createWithSpriteFrameName("A3_0.png"), this, menu_selector(GameHud::soldier3_Select)); item3->setPosition(ccp(210, 10)); CCMenuItemSprite * item4 = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("A4_0.png"), CCSprite::createWithSpriteFrameName("A4_0.png"), this, menu_selector(GameHud::soldier4_Select)); item4->setPosition(ccp(310, 10)); CCMenu* menu = CCMenu::create(item1,item2,item3,item4,NULL); menu->setPosition(ccp(100,30)); menu->setTag(10); this->addChild(menu); selectFlag = CCSprite::create("aim.png"); selectFlag->retain(); selectFlag->setScale(0.5f); selectFlag->setPosition( ccpAdd(item1->getPosition(), menu->getPosition())); this->addChild(selectFlag); CCLabelTTF* lab = CCLabelTTF::create("所需 100 援兵", "Arial-BoldMT", 20); lab->setColor(ccRED); lab->setTag(101); lab->setPosition(ccp(600, 40)); this->addChild(lab); CCMenuItemFont *add = CCMenuItemFont::create("增援", this, menu_selector(GameHud::click_addSoldier)); add->setPosition(CCPointZero); add->setFontSizeObj(35); add->setColor(ccRED); CCMenu *menu0 = CCMenu::createWithItem(add); menu0->setPosition( winsize.width-200, 40); this->addChild(menu0); CCMenuItemSprite* btn_attack = CCMenuItemSprite::create( CCSprite::createWithSpriteFrameName("btn_soldierattack1.png"), CCSprite::createWithSpriteFrameName("btn_soldierattack2.png"), this, menu_selector(GameHud::click_attack)); CCMenu* menu1 = CCMenu::createWithItem(btn_attack); menu1->setPosition(ccp(winsize.width-100,40)); this->addChild(menu1); soldier1_Select(item1); timerLab = CCLabelTTF::create("5", "Arial-BoldMT", 50); timerLab->setPosition(ccp(winsize.width/2, winsize.height/2)); this->addChild(timerLab); this->setTouchEnabled(true); this->schedule(schedule_selector(GameHud::countDown), 1.0f); MaskLayer* mask = MaskLayer::create(); this->addChild(mask); mask->setTag(11); GameRoot::shareGameRoot()->sethasStart(false); count =3; ret = true; } while (0); return ret; }
// on "init" you need to initialize your instance bool RectWorld::init() { bool bRet = false; do { ////////////////////////////////////////////////////////////////////////// // super init first ////////////////////////////////////////////////////////////////////////// CC_BREAK_IF(! CCLayer::init()); ////////////////////////////////////////////////////////////////////////// // add your codes below... ////////////////////////////////////////////////////////////////////////// // 1. Add a menu item with "X" image, which is clicked to quit the program. // Create a "close" menu item with close icon, it's an auto release object. CCMenuItemImage *pPauseItem = CCMenuItemImage::itemFromNormalImage("pause.png","pause.png",this,menu_selector(RectWorld::menuPause)); CC_BREAK_IF(! pPauseItem); // Place the menu item bottom-right conner. pPauseItem->setPosition(ccp(22, 22)); // Create a menu with the "close" menu item, it's an auto release object. CCMenu* pMenu = CCMenu::menuWithItems(pPauseItem, NULL); pMenu->setPosition(CCPointZero); pMenu->setTag(6); CC_BREAK_IF(! pMenu); // Add the menu to HelloWorld layer as a child layer. this->addChild(pMenu, 10); // Create a "close" menu item with close icon, it's an auto release object. // Create a menu with the "close" menu item, it's an auto release object. // Get window size and place the label upper. CCSize size = CCDirector::sharedDirector()->getWinSize(); // 3. Add add a splash screen, show the cocos2d splash image. // Place the sprite on the center of the screen MovingBackground *bk = MovingBackground::node(); this->addChild(bk); //CCParticleSystem *particle = ARCH_OPTIMAL_PARTICLE_SYSTEM::particleWithFile("tile.plist"); //particle->setPosition(ccp(_player->getContentSize().width / 2 + size.width / 5 * 3, size.height / 2)); //this->addChild(particle, 1); //this->schedule(schedule_selector(RectWorld::collision)); this->schedule(schedule_selector(RectWorld::gameLogic), 1.0); this->schedule(schedule_selector(RectWorld::update)); //CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this,0,true); if (_type == 3) { TimeLayer *timeLayer = TimeLayer :: node(); timeLayer->setInitalTime(60); timeLayer->setTag(4); this->addChild(timeLayer, 3); this->schedule(schedule_selector(RectWorld::clockPassBy), 1.0f); } bRet = true; } while (0); return bRet; }
void MainGameScene::makeResumeDaialog() { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); //CCSpriteで作ると、タッチ判定無効とかめんどくさいからBGもMenuItemで作る CCMenuItemImage* resumeBG = CCMenuItemImage::create("logo_Info2.png","logo_Info2.png"); resumeBG->setScale(0.7); resumeBG->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.5)); resumeBG->setEnabled(false); CCSize pResumeBGSize = resumeBG->getContentSize(); CCLabelTTF* resumeLabel; resumeLabel = CCLabelTTF::create(NKLocalizedString::LocalizedString("resume", "RESUME"), "Copperplate", 60.0); resumeLabel->setColor(ccc3(0, 0, 0)); resumeLabel->setPosition(ccp(pResumeBGSize.width * 0.5 ,pResumeBGSize.height * 0.7)); resumeBG->addChild(resumeLabel); CCMenuItemImage* titleItem = CCMenuItemImage::create("button1.png","button1.png" ,this, menu_selector(MainGameScene::tapTitleButton)); titleItem->setPosition(ccp(winSize.width * 0.3, winSize.height * 0.47)); CCLabelTTF* titleLabel; titleLabel = CCLabelTTF::create("TITLE", "Arial", 30.0); CCSize pTitleItemSize = titleItem->getContentSize(); titleLabel->setPosition(ccp(pTitleItemSize.width / 2 ,pTitleItemSize.height / 2)); titleItem->addChild(titleLabel); titleItem->setScale(0.8); CCMenuItemImage* returnGameItem = CCMenuItemImage::create("button2.png","button2.png" ,this, menu_selector(MainGameScene::returnMainGame)); returnGameItem->setPosition(ccp(winSize.width * 0.7, winSize.height * 0.47)); CCLabelTTF* returnGameLabel; returnGameLabel = CCLabelTTF::create("CANCEL", "Arial", 30.0); CCSize pReturnGameSize = returnGameItem->getContentSize(); returnGameLabel->setPosition(ccp(pReturnGameSize.width / 2 ,pReturnGameSize.height / 2)); returnGameItem->addChild(returnGameLabel); returnGameItem->setScale(0.8); CCMenuItemImage* retryGameItem = CCMenuItemImage::create("button3.png","button3.png" ,this, menu_selector(MainGameScene::doRetry)); retryGameItem->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.39)); CCLabelTTF* retryGameLabel; retryGameLabel = CCLabelTTF::create("RETRY", "Arial", 30.0); CCSize pRetryGameSize = retryGameItem->getContentSize(); retryGameLabel->setPosition(ccp(pRetryGameSize.width / 2 ,pRetryGameSize.height / 2)); retryGameItem->addChild(retryGameLabel); retryGameItem->setScale(0.8); CCMenu* resumeDialog = CCMenu::create(resumeBG, titleItem, returnGameItem,retryGameItem,NULL); resumeDialog->setPosition(CCPointZero); resumeDialog->setTag(tagResumeDialog); resumeDialog->setOpacity(0); resumeDialog->setZOrder(Z_ORDER_RESUME_DIALOG); resumeDialog->setEnabled(false); this->addChild(resumeDialog); }
void TanSuoLayer::menuItemClicked_TanSuo(CCObject *pSender) { int tag = ((CCMenuItem*)pSender)->getTag(); if (tag == Tag_MenuItem_YiJianTanSuo) { if (m_bIsJieFeng) { string infoStr = LFStrings::getValue("XuYaoJieFeng"); UnblockWarnDialog* pDlg = UnblockWarnDialog::create(infoStr); CCDirector::sharedDirector()->getRunningScene()->addChild(pDlg, 300); return; } if (MyselfManager::getManager()->getMyZhuJueData()->getVipLevel() < 3) { FXToast *layer = FXToast::create(LFStrings::getValue("XunBao_VipNeed")); CCDirector::sharedDirector()->getRunningScene()->addChild(layer); return; } m_bDiscoverAll = true; addObserver(callfuncO_selector(TanSuoLayer::rsp_tansuo), MSG_discoverRsp); mCmdHlp->cmdDiscover(m_bDiscoverAll); } else if (tag == Tag_MenuItem_TanSuo) { m_bDiscoverAll = false; addObserver(callfuncO_selector(TanSuoLayer::rsp_tansuo), MSG_discoverRsp); mCmdHlp->cmdDiscover(m_bDiscoverAll); } else if (tag == Tag_MenuItem_JieFen) { if (mDestroyCount >= m_nMaxCountDestroy) { m_bIsJieFeng = true; m_nSelectProId = -1; if (! EquipmentManager::getManager()->isSpareEnoughToSaveEquip(1)) { EquipBagNotEnoughDialog *layer = new EquipBagNotEnoughDialog; layer->showGoToFenJieDialog(); } CCSize visSize = CCDirector::sharedDirector()->getWinSize(); BaseSprite* dialog = BaseSprite::create("juqing_duihuakuang.png"); dialog->setPosition(ccp(visSize.width/2, visSize.height/2)); //label 提示 { /*CCLabelTTF* label = CCLabelTTF::create(LFStrings::getValue("XunBao_XuanZeHeroTiShi").c_str(), fontStr_kaiti, m_nFontSize, CCSize(425, 0), kCCTextAlignmentLeft); label->setAnchorPoint(ccp(0.5, 1)); label->setPosition(ccp(dialog->getContentSize().width/2, 250)); dialog->addChild(label, 1);*/ CCLabelTTF *title = CCLabelTTF::create(LFStrings::getValue("JieChuFengYin").c_str(),fontStr_kaiti,m_nFontSize); title->setAnchorPoint(ccp(0.5,1)); title->setPosition(ccp(dialog->getContentSize().width/2, 250)); dialog->addChild(title, 1); CCLabelTTF *chuanqi = CCLabelTTF::create(LFStrings::getValue("ChuanQiZhuangBei").c_str(),fontStr_kaiti,m_nFontSize); chuanqi->setAnchorPoint(ccp(0.5,1)); chuanqi->setPosition(ccp(title->getPositionX() - title->getContentSize().width / 2 + m_nFontSize * 7 + chuanqi->getContentSize().width / 2, 250)); dialog->addChild(chuanqi, 1); chuanqi->setColor(ccc3(235,106,12)); } { m_lMenuItemList.clear(); //mHeros = MyselfManager::getManager()->getTeamActors_ZhenShen(Actor_All, LF_UnLock); mHeros = MyselfManager::getManager()->getTeamActors_ZhenShen(Actor_ShangZheng, LF_UnLock); //tabel view CCTableView *tabelView = CCTableView::create(this, CCSizeMake(560, 158)); tabelView->setDirection(kCCScrollViewDirectionHorizontal); tabelView->setPosition(ccp(41, 44)); tabelView->setDelegate(this); dialog->addChild(tabelView); tabelView->reloadData(); } //确认 取消按键 CCMenu* menu = CCMenu::create(); menu->setPosition(CCPointZero); menu->setTag(0); // { LFAlert* lfAlert = new LFAlert(); lfAlert->setTag(TAG_AwardDisplayer_Layer); lfAlert->setBaseContainer(dialog,menu); lfAlert->setZoneCanotTouch(); CCDirector::sharedDirector()->getRunningScene()->addChild(lfAlert,128, TAG_AwardDisplayer_Layer); lfAlert->release(); } return; } else { MessageDisplay* layer = MessageDisplay::create("ERROR!"); CCDirector::sharedDirector()->getRunningScene()->addChild(layer); return; } } }