bool HSGoldInadequateDialog::InitDialog() { CCSprite* pBackground = CCSprite::create("Image/SelectChannel/goumaijinbidikuang.png"); pBackground->setPosition(ccp(307,480)); this->addChild(pBackground); CCSprite* pGoldFrame = CCSprite::create("Image/SelectChannel/Mingziditu.png"); pGoldFrame->setPosition(ccp(236,202)); pBackground->addChild(pGoldFrame); CCSprite* pMoneyFrame = CCSprite::create("Image/SelectChannel/Mingziditu.png"); pMoneyFrame->setPosition(ccp(520,202)); pBackground->addChild(pMoneyFrame); const message::PropInfoData* pPropInfodata = HS_GAME_CACHE()->GetPropInfoData(); for (int i =0;i<pPropInfodata->buygoldlist_size();++i) { int temp = pPropInfodata->buygoldlist(i).gold_number(); if ((int)m_buyGold.gold_number() < temp) { m_buyGold = pPropInfodata->buygoldlist(i); } if (temp > HS_GAME_CACHE()->GetGold()) { m_buyGold = pPropInfodata->buygoldlist(i); break; } } CCLabelTTF* pGoldTTF = CCLabelTTF::create(CCString::createWithFormat("%d",m_buyGold.gold_number())->getCString(),HS_FONT_HuaKang,36.f); pGoldTTF->setAnchorPoint(HS_ANCHOR_L_CENTER); pGoldTTF->setPosition(ccp(0,pGoldTTF->getContentSize().height - pGoldTTF->getFontSize() / 2.f)); pGoldFrame->addChild(pGoldTTF); CCLabelTTF* pMoneyTTF = CCLabelTTF::create(CCString::createWithFormat("%d",m_buyGold.money())->getCString(),HS_FONT_HuaKang,36.f); pMoneyTTF->setAnchorPoint(HS_ANCHOR_L_CENTER); pMoneyTTF->setPosition(ccp(0,pMoneyTTF->getContentSize().height - pMoneyTTF->getFontSize() / 2.f)); pMoneyFrame->addChild(pMoneyTTF); CCMenuItem* pGoRoomItem = CCMenuItemImage::create("Image/SelectChannel/dibeilvchang_01.png","Image/SelectChannel/dibeilvchang_02.png",this,menu_selector(HSGoldInadequateDialog::Call_GoRoom)); pGoRoomItem->setPosition(ccp(169,322)); this->PushMenu(pGoRoomItem); CCMenuItem* pBuyItem = CCMenuItemImage::create("Image/SelectChannel/goumai_01.png","Image/SelectChannel/goumai_02.png",this,menu_selector(HSGoldInadequateDialog::Call_Buy)); pBuyItem->setPosition(ccp(456,322)); this->PushMenu(pBuyItem); return true; }
void IntroScene::createUI() { // Add background image CCSprite* bg_spt = CCSprite::create(getResPath(INTRO_BACKGROUND_IMGAE)); bg_spt->setScaleX(SCALEX); bg_spt->setScaleY(SCALEY); bg_spt->setPosition(ccp(winSize.width * 0.5, winSize.height * 0.5)); this->addChild(bg_spt); // Add description bg CCSprite* des_bg = CCSprite::create(getResPath(INTRO_DESCRIPTION_BG_IMG)); des_bg->setScaleX(SCALEX); des_bg->setScaleY(SCALEY * 0.5); des_bg->setPosition(ccp(winSize.width * 0.5, 798 * SCALEY)); this->addChild(des_bg); // Add description text CCSprite* des = CCSprite::create(getResPath(INTRO_DESCRIPTION_IMG)); des->setScale(MIN(SCALEX, SCALEY)); des->setPosition(ccp(winSize.width * 0.5, 800 * SCALEY)); this->addChild(des); // Add character CCSprite* character = CCSprite::create(getResPath(INTRO_CHARACTER_IMG)); character->setScale(SCALE * 0.9); character->setPosition(ccp(167 * SCALEX, 385 * SCALEY)); this->addChild(character); // Add blue and yellow chair CCSprite* bl_chair = CCSprite::create(getResPath(CHAIR_BLUE_IMG)); bl_chair->setScale(SCALE * 0.9); bl_chair->setPosition(ccp(140 * SCALEX, 243 * SCALEY)); this->addChild(bl_chair); CCSprite* yl_chair = CCSprite::create(getResPath(CHAIR_YELLOW_IMG)); yl_chair->setScale(SCALE * 0.9); yl_chair->setPosition(ccp(506 * SCALEX, 243 * SCALEY)); this->addChild(yl_chair); // Add play, mainmenu buttons CCMenuItem* playItem = CCMenuItemImage::create(getResPath(INTRO_PLAY_BUTTON_IMAGE_NOR), getResPath(INTRO_PLAY_BUTTON_IMAGE_PRS), this, menu_selector(IntroScene::gotoplay)); playItem->setScale(MIN(SCALEX, SCALEY)); playItem->setPosition(175 * SCALEX, 50 * SCALEY); CCMenuItem* mainmenuItem = CCMenuItemImage::create(getResPath(INTRO_MAINMENU_BUTTON_IMAGE_NOR), getResPath(INTRO_MAINMENU_BUTTON_IMAGE_PRS), this, menu_selector(IntroScene::gotoMainMenu)); mainmenuItem->setScale(MIN(SCALEX, SCALEY)); mainmenuItem->setPosition(467 * SCALEX, 50 * SCALEY); CCMenu* menu = CCMenu::create(playItem, mainmenuItem, NULL); menu->setPosition(CCPointZero); this->addChild(menu); }
void GameUI_MainTitle_Store::Init_Button() { CCMenuItem* eraser = CCMenuItemImage::create("b_buy.png", "b_buy.png", this,menu_selector(GameUI_MainTitle_Store::ButtonDelegate_Eraser)); CCMenuItem* undo = CCMenuItemImage::create("b_buy.png", "b_buy.png", this,menu_selector(GameUI_MainTitle_Store::ButtonDelegate_Undo)); eraser->setPosition(ccp(533, 1280-413)); undo->setPosition(ccp(533, 1280-652)); CCMenu* menu = CCMenu::create(eraser, undo, NULL); menu->setPosition(ccp(0,0)); this->addChild(menu); }
void MapMenu::addMenu() { if (spriteBackButton != NULL) { spriteBackButton->removeFromParentAndCleanup(false); } spriteBackButton = CCSprite::create("Background_Estacionamento_botoes.png"); spriteBackButton->setAnchorPoint(ccp(0, 0)); CCSize winsize = CCDirector::sharedDirector()->getWinSize(); if (winsize.height > 480) { spriteBackButton->setPosition(ccp(0, 430)); } else { spriteBackButton->setPosition(ccp(0, 350)); } layer->addChild(spriteBackButton, 100) ; CCMenuItem *pOpenMapItem; CCMenuItem *pOpen3DItem; if(type == MAP_NORMAL ) { pOpenMapItem = CCMenuItemImage::create("button_comochegar_pressed.png","button_comochegar_pressed.png",this,menu_selector(MapMenu::openMap)); pOpen3DItem = CCMenuItemImage::create("button_3d_on.png","button_3d_on.png",this,menu_selector(MapMenu::open3D)); } else { pOpenMapItem = CCMenuItemImage::create("button_comochegar_on.png","button_comochegar_on.png",this,menu_selector(MapMenu::openMap)); pOpen3DItem = CCMenuItemImage::create("button_3d_pressed.png","button_3d_pressed.png",this,menu_selector(MapMenu::open3D)); } pOpenMapItem->setAnchorPoint(ccp(0, 0)); pOpenMapItem->setPosition(ccp(0, 0)); pOpen3DItem->setAnchorPoint(ccp(0, 0)); pOpen3DItem->setPosition(ccp(110, 00)); // pCloseItem->setFontSize(35); // pCloseItem->setFontName("Helvetica"); if (menu != NULL) { menu->removeFromParentAndCleanup(false); } menu = CCMenu::create(pOpenMapItem,pOpen3DItem,NULL); menu->setAnchorPoint(ccp(0, 0)); if (winsize.height > 480) { menu->setPosition(ccp(50, 450)); } else { menu->setPosition(ccp(50, 360)); } layer->addChild(menu,101); }
bool CChooseLetterWindow::init() { m_Back = Sprite::create("choose_letter.png"); m_Back->setPosition(600,384); m_Back->setVisible(false); addChild(m_Back); std::vector<char> m_Letters; m_Letters.resize(26); m_Letters[0] = 'a'; m_Letters[1] = 'b'; m_Letters[2] = 'c'; m_Letters[3] = 'd'; m_Letters[4] = 'e'; m_Letters[5] = 'f'; m_Letters[6] = 'g'; m_Letters[7] = 'h'; m_Letters[8] = 'i'; m_Letters[9] = 'j'; m_Letters[10] = 'k'; m_Letters[11] = 'l'; m_Letters[12] = 'm'; m_Letters[13] = 'n'; m_Letters[14] = 'o'; m_Letters[15] = 'p'; m_Letters[16] = 'q'; m_Letters[17] = 'r'; m_Letters[18] = 's'; m_Letters[19] = 't'; m_Letters[20] = 'u'; m_Letters[21] = 'v'; m_Letters[22] = 'w'; m_Letters[23] = 'x'; m_Letters[24] = 'y'; m_Letters[25] = 'z'; float startPosX = -460.0f; float startPosY = -150.0f; float stepX = 45.0f; float stepY = 45.0f; int columnCount = 6; int rowCount = 4; int id = 0; int currentColumn = 0; int currentRow = 0; m_pMenu = CCMenu::create(); for(int i=0;i<m_Letters.size();i++) { Point pos = Point(startPosX+(currentColumn*stepX),startPosY+(-currentRow*stepY)); CCMenuItem * button = CCMenuItemImage::create( "base.png", "fixed.png", this, menu_selector(CChooseLetterWindow::LetterBtnClick)); button->setTag(int(m_Letters[i])); button->setScale(0.35f); button->setPosition(pos); LabelTTF * letterLabel = LabelTTF::create("0","helvetica",82); letterLabel->setPosition(button->getContentSize().width/2,button->getContentSize().height/2); letterLabel->setColor(Color3B(0,0,0)); std::string str = "A"; str[0] = m_Letters[i]; std::transform(str.begin(), str.end(),str.begin(), ::toupper); letterLabel->setString(str); button->addChild(letterLabel); //letterLabel->setPosition(pos); currentColumn++; if(currentColumn == columnCount) { currentColumn = 0; currentRow++; } m_pMenu->addChild(button); m_pMenu->setEnabled(false); } m_Back->addChild(m_pMenu); return true; }
bool HSGoldInadequateDialog::InitDialog() { CCSprite* pBackground = HSCCSprite::create("Image/goumaijinbidikuang.png"); pBackground->setPosition(ccp(307,480)); this->addChild(pBackground); CCSprite* pGoldFrame = HSCCSprite::create("Image/Mingziditu.png"); pGoldFrame->setPosition(ccp(236,202)); pBackground->addChild(pGoldFrame); CCSprite* pMoneyFrame = HSCCSprite::create("Image/Mingziditu.png"); pMoneyFrame->setPosition(ccp(520,202)); pBackground->addChild(pMoneyFrame); m_pGoldTTF = CCLabelTTF::create(CCString::createWithFormat("%d",0/*m_buyGold->gold_number()*/)->getCString(),HS_FONT_HuaKang,36.f); m_pGoldTTF->setAnchorPoint(HS_ANCHOR_L_CENTER); m_pGoldTTF->setPosition(ccp(0,m_pGoldTTF->getContentSize().height - m_pGoldTTF->getFontSize() / 2.f)); pGoldFrame->addChild(m_pGoldTTF); m_pMoneyTTF = CCLabelTTF::create(CCString::createWithFormat("%d",0/*m_buyGold->money()*/)->getCString(),HS_FONT_HuaKang,36.f); m_pMoneyTTF->setAnchorPoint(HS_ANCHOR_L_CENTER); m_pMoneyTTF->setPosition(ccp(0,m_pMoneyTTF->getContentSize().height - m_pMoneyTTF->getFontSize() / 2.f)); pMoneyFrame->addChild(m_pMoneyTTF); CCNode* pItemNode_01 = HSCCSprite::create("Image/dibeilvchang_01.png"); CCNode* pItemNode_02 = HSCCSprite::create("Image/dibeilvchang_02.png"); CCMenuItem* pGoRoomItem = CCMenuItemSprite::create(pItemNode_01,pItemNode_02,this,menu_selector(HSGoldInadequateDialog::Call_GoRoom)); pGoRoomItem->setPosition(ccp(169,322)); this->PushMenu(pGoRoomItem); CCNode* pItemNode_03 = HSCCSprite::create("Image/goumai_01.png"); CCNode* pItemNode_04 = HSCCSprite::create("Image/goumai_02.png"); CCMenuItem* pBuyItem = CCMenuItemSprite::create(pItemNode_03,pItemNode_04,this,menu_selector(HSGoldInadequateDialog::Call_Buy)); pBuyItem->setPosition(ccp(456,322)); this->PushMenu(pBuyItem); return true; }
void CCMenuItemToggle::setSelectedIndex(unsigned int index) { if( index != m_uSelectedIndex ) { m_uSelectedIndex = index; this->removeChildByTag(kCurrentItem, false); CCMenuItem *item = m_pSubItems->getObjectAtIndex(m_uSelectedIndex); this->addChild(item, 0, kCurrentItem); CGSize s = item->getContentSize(); this->setContentSize(s); item->setPosition( ccp( s.width/2, s.height/2 ) ); } }
void ADAds::fillBanner(Banner* banner) { #if defined(_DEBUG) && CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 CCRenderTexture* texture = CCRenderTexture::create(100, 100); texture->beginWithClear(0.5f, 0.5f, 0.5f, 1); texture->end(); CCSprite* s = CCSprite::createWithTexture(texture->getSprite()->getTexture()); s->setScaleX(banner->getContentSize().width/s->getContentSize().width); s->setScaleY(banner->getContentSize().height/s->getContentSize().width); banner->addChild(s); s->setAnchorPoint(ccp(0,0)); s->setPosition(ccp(0,0)); #endif if(_home_banners.size()) { //std::random_shuffle(_home_banners.begin(), _home_banners.end()); CustomBanner* home_ads = getCustomBanner(); CCMenuItem* item = CCMenuItem::create( home_ads, menu_selector(CustomBanner::onClick)); CCMenu* menu = CCMenu::create(); menu->addChild(item); banner->addChild(menu, 0, HOME_ADS_NODE_TAG); menu->setAnchorPoint(ccp(0,0)); menu->setPosition(ccp(0,0)); CCNode* banner_content = home_ads->getBanner(); CCSize content_size = banner_content->getContentSize(); CCSize zone_size = banner->getContentSize(); float scale = MIN(zone_size.width/content_size.width, zone_size.height/content_size.height); banner_content->setScale(scale); banner_content->setAnchorPoint(ccp(0, 0)); banner_content->setPosition(ccp(0,0)); item->setContentSize(content_size*scale); item->setAnchorPoint(ccp(0.5f,0.5f)); item->setPosition(zone_size*0.5f); item->addChild(banner_content); } }
void DropDownListSprite:: addLabel(CCLabelTTF * label) { CCSize size = getContentSize(); CCLayerColor * normal = CCLayerColor::create(DROPDOWNLIST_NORMAL_COLOR,size.width,size.height); CCLayerColor * selected = CCLayerColor::create(DROPDOWNLIST_SELECTED_COLOR, size.width, size.height); m_bgLayers.push_back(normal); m_selectLabels.push_back(label); CCMenuItem * item = CCMenuItemSprite::create(normal, selected, NULL,this, SEL_MenuHandler(&DropDownListSprite::onSelected)); label->setPosition(ccp(size.width/2, size.height/2)); item->addChild(label); item->setTag((int)m_selectLabels.size()-1); item->setPosition(ccp(0,- (int)m_selectLabels.size() * size.height)); m_mainMenu->addChild(item); }
void CCMenuItemToggle::setSelectedIndex(unsigned int index) { if( index != m_uSelectedIndex && m_pSubItems->count() > 0 ) { m_uSelectedIndex = index; CCMenuItem *currentItem = (CCMenuItem*)getChildByTag(kCurrentItem); if( currentItem ) { currentItem->removeFromParentAndCleanup(false); } CCMenuItem* item = (CCMenuItem*)m_pSubItems->objectAtIndex(m_uSelectedIndex); this->addChild(item, 0, kCurrentItem); CCSize s = item->getContentSize(); this->setContentSize(s); item->setPosition( ccp( s.width/2, s.height/2 ) ); } }
GetPeanuts::GetPeanuts() { // enable touches setTouchEnabled( true ); float scale = ScreenHelper::getTextureScale(); float scaleX = ScreenHelper::getTextureScaleX(); float scaleY = ScreenHelper::getTextureScaleY(); CCSprite *spriteReturn = CCSprite::createWithSpriteFrameName("ctm_Store_Shopping_Btn.png"); CCSprite *spriteReturnDown = CCSprite::createWithSpriteFrameName("ctm_Store_Shopping_Btn_Down.png"); CCMenuItem *returnButton = CCMenuItemSprite::create(spriteReturn,spriteReturnDown,this,menu_selector(GetPeanuts::returnButtonTapped)); returnButton->setScale(scale); returnButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT,90.0f,130.0f)); CCMenu* backmenu = CCMenu::create(returnButton, NULL); backmenu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_BOTTOM_LEFT)); addChild(backmenu,4); setPosition(CCPointMake(-480*scaleX, 0)); runAction(CCMoveBy::create(0.15f,CCPointMake(480*scaleX, 0))); bMenuBuilt = false; isReturning = false; if(SaveLoad::m_SaveData.beenToPeanuts==0) { SaveLoad::m_SaveData.beenToPeanuts=1; SaveLoad::Save(); // [TestFlight passCheckpoint:@"PEANUT_VISIT"]; } scheduleUpdate(); }
Options::Options() { setTouchEnabled( true ); float scale = ScreenHelper::getTextureScale(); float scaleX = ScreenHelper::getTextureScaleX(); float scaleY = ScreenHelper::getTextureScaleY(); CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Buttons.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Buttons.plist"); CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Icons.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Icons.plist"); CCSprite *sprite = CCSprite::create("MainBackFiller.png"); sprite->setScaleX(scaleX*1.2f); sprite->setScaleY(scaleY*1.2f); sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,0.0f,-32.0f)); addChild(sprite); sprite = CCSprite::create("ctm_UI_topOverlayA_ver1.png"); sprite->setScaleX(scaleX); sprite->setScaleY(scaleY); sprite->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER)); addChild(sprite,2); CCLabelTTF *label = CCLabelTTF::create("OPTIONS", "impact.ttf", 42*scale); addChild(label, 2); label->setColor(ccc3(0,0,0)); label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,2.0f,-52.0f)); label = CCLabelTTF::create("OPTIONS", "impact.ttf", 42*scale); addChild(label, 2); label->setColor(ccc3(237,188,0)); label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-50.0f)); CCMenuItem *BackButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ctm_Back_Button.png"), CCSprite::createWithSpriteFrameName("ctm_Back_Button_Down.png"), this, menu_selector(Options::backButtonTapped)); BackButton->setScale(scale); BackButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_LEFT,50.0f,-50.0f)); CCMenuItem *QuestionMarkButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ctm_Button_20.png"), CCSprite::createWithSpriteFrameName("ctm_Button_20_Down.png"), this, menu_selector(Options::questionButtonTapped)); QuestionMarkButton->setScale(scale); QuestionMarkButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_CENTER,0.0f,65.0f)); CCMenuItem *MoreGamesButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("MoreGames.png"), CCSprite::createWithSpriteFrameName("MoreGames_dn.png"), this, menu_selector(Options::moreGamesButtonTapped)); MoreGamesButton->setScale(scale); MoreGamesButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT,55.0f,65.0f)); CCMenuItem *CreditsButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("Credits.png"), CCSprite::createWithSpriteFrameName("Credits_dn.png"), this, menu_selector(Options::creditsButtonTapped)); CreditsButton->setScale(scale); CreditsButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_RIGHT,-55.0f,65.0f)); CCLabelTTF *optionsLabel = NULL; if(SaveLoad::m_SaveData.sfxVolume <= 0.0f) optionsLabel = CCLabelTTF::create("SFX: OFF", "impact.ttf", 40*scale); else optionsLabel = CCLabelTTF::create("SFX: ON", "impact.ttf", 40*scale); CCMenuItemLabel *SoundFX = CCMenuItemLabel::create(optionsLabel, this, menu_selector(Options::sfxButtonTapped)); SoundFX->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER, 0, 20)); if(SaveLoad::m_SaveData.musicVolume <= 0.0f) optionsLabel = CCLabelTTF::create("Music: OFF", "impact.ttf", 40*scale); else optionsLabel = CCLabelTTF::create("Music: ON", "impact.ttf", 40*scale); CCMenuItemLabel *Music = CCMenuItemLabel::create(optionsLabel, this, menu_selector(Options::musicButtonTapped)); Music->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER, 0, -20)); CCMenu* menu = CCMenu::create(BackButton, QuestionMarkButton, MoreGamesButton, CreditsButton, SoundFX, Music, NULL); menu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_BOTTOM_LEFT)); addChild(menu,4); scheduleUpdate(); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } this->isTouchEnabled(); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object //CCMenuItemImage *pCloseItem = CCMenuItemImage::create( // "CloseNormal.png", // "CloseSelected.png", // this, // menu_selector(HelloWorld::menuCloseCallback)); //pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , //origin.y + pCloseItem->getContentSize().height/2)); CCMenuItem *pStartGameItem = CCMenuItemFont::create( "Start Game", this, menu_selector(HelloWorld::startGame) ); pStartGameItem->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2)); CCMenuItem *pGameOptions = CCMenuItemFont::create( "Options", this, menu_selector(HelloWorld::startOptionsMenu) ); pGameOptions->setPosition(ccp(origin.x + visibleSize.width - pGameOptions->getContentSize().width/2 , origin.y + pGameOptions->getContentSize().height/2)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pStartGameItem, NULL); pMenu->setPosition(CCPointZero); pMenu->addChild(pGameOptions); this->addChild(pMenu, 1); ///////////////////////////// // 3. add your codes below... // add "HelloWorld" splash screen" CCSprite* pSprite = CCSprite::create("HelloWorld.png"); // position the sprite on the center of the screen pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(pSprite, 0); CCLabelTTF* pLabel = CCLabelTTF::create("Ugly Brick Breaker EXTREME V0.1", "Arial", TITLE_FONT_SIZE); // position the label on the center of the screen pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); // add the label as a child to this layer this->addChild(pLabel, 1); CCLabelTTF* authorLabel = CCLabelTTF::create("By: Steven Bauer", "Arial", TITLE_FONT_SIZE); authorLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - 30 - authorLabel->getContentSize().height)); this->addChild(authorLabel, 2); return true; }
CCLayer* RemindLayer::createRLayer(const char *tStr, int remindType){ CCLayer* layer = new CCLayer(); int tagOpen = 0; int tagClose = 0; bool typeOn; switch (remindType) { case EN_REMIND_ACTIVITY: tagOpen = kActivityOnTag; tagClose = kActivityOffTag; typeOn = CGameData::Inst()->isActivityRemind; break; case EN_REMIND_TWOUP: tagOpen = kTwoupOnTag; tagClose = kTwoupOffTag; typeOn = CGameData::Inst()->isTwoUpRemind; break; case EN_REMIND_CNTRYCD: tagOpen = kCntryCdOnTag; tagClose = kCntryCdOffTag; typeOn = CGameData::Inst()->isCntryCdRemind; break; case EN_REMIND_POWER:{ tagOpen = kPowerOnTag; tagClose = kPowerOffTag; typeOn = CGameData::Inst()->intPowerRemind; CCSprite* spMenu1 = CCSprite::spriteWithFile("pushConfig_tilizhi.png"); CCSprite* spMenu2 = CCSprite::spriteWithFile("pushConfig_tilizhi.png"); CCMenuItem* item = CCMenuItemImage::itemFromNormalSprite(spMenu1,spMenu2, this, menu_selector(RemindLayer::MoveUpKeyboard)); item->setPosition(ccp(0,0)); item->setAnchorPoint(CCPointZero); CCMenu *menu = CCMenu::menuWithItems (item, NULL); menu->setPosition(ccp(-50,20)); layer->addChild(menu, 2); char buf[100]; snprintf(buf, 99,"%d", CGameData::Inst()->intPowerRemind); powerNumber = CCTextFieldTTF::textFieldWithPlaceHolder(buf,CCSizeMake(100, 200) ,CCTextAlignmentCenter,"huakangfont.ttf", 32); powerNumber->setPosition(ccp(12, 40)); powerNumber->setColor(ccWHITE); powerNumber->setDelegate(this); layer->addChild(powerNumber,10); CCEGLView * pGlView = CCDirector::sharedDirector()->getOpenGLView(); pGlView->setIMEKeyboardNumber(); break; } default: tagOpen = kActivityOnTag; tagClose = kActivityOffTag; typeOn = CGameData::Inst()->isCntryCdRemind; break; } CCSprite* spFrame = CCSprite::spriteWithFile("pushConfig_Bg.png"); spFrame->setPosition(CCPointMake(2, 0)); layer->addChild(spFrame); TextNode *remindLabel = TextNode::textWithString(tStr, 32); remindLabel->setColor(ccc3(255, 255, 255)); remindLabel->setShadowColor(ccc3(0, 0, 0)); remindLabel->setPosition(ccp(0,40)); layer->addChild(remindLabel); CCSprite* spMenu1 = CCSprite::spriteWithSpriteFrameName("fr_open.png"); CCSprite* spMenu2 = CCSprite::spriteWithSpriteFrameName("fr_open.png"); CCSprite* spMenu3 = CCSprite::spriteWithSpriteFrameName("fr_open2.png"); CCMenuItem* item1 = CCMenuItemImage::itemFromNormalSprite(spMenu1,spMenu2,spMenu3, this, menu_selector(RemindLayer::switchOnOff)); item1->setPosition(ccp(-170, -50)); item1->setAnchorPoint(ccp(0, 0)); item1->setTag(tagOpen); spMenu1 = CCSprite::spriteWithSpriteFrameName("fr_close.png"); spMenu2 = CCSprite::spriteWithSpriteFrameName("fr_close.png"); spMenu3 = CCSprite::spriteWithSpriteFrameName("fr_close2.png"); CCMenuItem* item2 = CCMenuItemImage::itemFromNormalSprite(spMenu1,spMenu2,spMenu3, this, menu_selector(RemindLayer::switchOnOff)); item2->setPosition(ccp(30, -50)); item2->setAnchorPoint(ccp(0, 0)); item2->setTag(tagClose); item1->setIsEnabled(!typeOn); item2->setIsEnabled(typeOn); CCMenu *menu = CCMenu::menuWithItems (item1,item2, NULL); menu->setPosition(ccp(0, 0)); layer->addChild(menu); return layer; }
bool CSLayerPopupMsg::init(POPUPMSG_ENUM popEnum, string strTitle, string strMessage) { m_strMessage = strMessage; m_strTitle = strTitle; m_popEnum = popEnum; CCSize size = CCDirector::sharedDirector()->getWinSize(); //添加背景 CCSprite *pSprite = CCSprite::spriteWithSpriteFrameName(m_strBackground.c_str()); pSprite->setPosition(ccp(size.width/2, size.height/2)); addChild(pSprite); //标题栏 CCLabelTTF *pLabel = CCLabelTTF::labelWithString(m_strTitle.c_str(), "DFPHaiBaoW12-GB", 28); pLabel->setPosition(ccp(size.width*2/5, size.height*7/10)); pLabel->setColor(ccc3(200,200,255)); pSprite->addChild(pLabel); //信息 pLabel = CCLabelTTF::labelWithString(m_strMessage.c_str(), "DFPHaiBaoW12-GB", 28); pLabel->setPosition(ccp(size.width/2, size.height/2)); pLabel->setColor(ccc3(155,155,255)); pSprite->addChild(pLabel); //添加按钮 CCMenu *pMenu = CCMenu::menuWithItems(NULL); pMenu->setPosition(CCPointZero); CCMenuItem *pItem; if (m_popEnum == POPUP_YESNOCANCEL) { pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0023.png", "Images/UI/common/0023.png", this, menu_selector(CSLayerPopupMsg::callbackClick)); pItem->setTag(RESPONSE_YES); pItem->setPosition(ccp(size.width*3/10, size.height*2/5)); pMenu->addChild(pItem, 0); pLabel = CCLabelTTF::labelWithString("确认", "DFPHaiBaoW12-GB", 28); pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2)); pItem->addChild(pLabel); pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0022.png", "Images/UI/common/0022.png", this, menu_selector(CSLayerPopupMsg::callbackClick)); pItem->setTag(RESPONSE_NO); pItem->setPosition(ccp(size.width*5/10, size.height*2/5)); pMenu->addChild(pItem, 0); pLabel = CCLabelTTF::labelWithString("取消", "DFPHaiBaoW12-GB", 28); pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2)); pItem->addChild(pLabel); pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0022.png", "Images/UI/common/0022.png", this, menu_selector(CSLayerPopupMsg::callbackClick)); pItem->setTag(RESPONSE_CANCEL); pItem->setPosition(ccp(size.width*7/10, size.height*2/5)); pMenu->addChild(pItem, 0); pLabel = CCLabelTTF::labelWithString("关闭", "DFPHaiBaoW12-GB", 28); pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2)); pItem->addChild(pLabel); } else if (m_popEnum == POPUP_YESNO) { pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0023.png", "Images/UI/common/0023.png", this, menu_selector(CSLayerPopupMsg::callbackClick)); pItem->setTag(RESPONSE_YES); pItem->setPosition(ccp(size.width*3/10, size.height*2/5)); pMenu->addChild(pItem, 0); pLabel = CCLabelTTF::labelWithString("确认", "DFPHaiBaoW12-GB", 28); pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2)); pItem->addChild(pLabel); pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0022.png", "Images/UI/common/0022.png", this, menu_selector(CSLayerPopupMsg::callbackClick)); pItem->setTag(RESPONSE_NO); pItem->setPosition(ccp(size.width*5/10, size.height*2/5)); pMenu->addChild(pItem, 0); pLabel = CCLabelTTF::labelWithString("取消", "DFPHaiBaoW12-GB", 28); pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2)); pItem->addChild(pLabel); } else if (m_popEnum == POPUP_YES) { pItem = CCMenuItemImage::itemFromNormalImage("Images/UI/common/0023.png", "Images/UI/common/0023.png", this, menu_selector(CSLayerPopupMsg::callbackClick)); pItem->setTag(RESPONSE_YES); pItem->setPosition(ccp(size.width*3/10, size.height*2/5)); pMenu->addChild(pItem, 0); pLabel = CCLabelTTF::labelWithString("确认", "DFPHaiBaoW12-GB", 28); pLabel->setPosition(ccp(pItem->getContentSize().width/2, pItem->getContentSize().height/2)); pItem->addChild(pLabel); } addChild(pMenu); return true; }
// on "init" you need to initialize your instance bool TableBar::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } //每个项目都要创建的东西 _menu = CCMenu::create(NULL); _menu->setPosition(CCPointZero); this->addChild(_menu, zNum+1); pTabBar = CCSprite::create("pTabBar.png"); pTabBar->setPosition(ccp(1024.0,49.0)); this->addChild(pTabBar,zNum); m_highlightSp = CCSprite::create("pTabBarSelectedHighlight.png"); string plistStr = TableBar::classPlistName; plistStr += ".plist"; plistDic = CCDictionary::createWithContentsOfFile(plistStr.c_str()); for (int i = 0; i<itemVec.size(); i++) { const char * picNameStr = (itemVec[i]+".png").c_str(); CCSprite * aSprite = CCSprite::create(picNameStr); if (i == TableBar::mainItemNum) { mainitemSprite = aSprite; } const char * positionName = itemVec[i].c_str(); aSprite->setPosition(ScriptParser::getPositionFromPlist(plistDic,positionName)); this->addChild(aSprite,zNum); CCMenuItem * aItem = CCMenuItem::create(this, menu_selector(TableBar::menuselect)); aItem->setPosition(aSprite->getPosition()); aItem->setContentSize(m_highlightSp->getContentSize()); _menu ->addChild(aItem,zNum); aItem->setTag(i); const char * itemTitleStr = itemTitleVec[i].c_str(); CCLabelTTF* pLabel = CCLabelTTF::create(itemTitleStr,fontName_macro,fontSize_macro); if (i == TableBar::mainItemNum) { pLabel->setColor(White_macro); } else { pLabel->setColor(gray_macro); } const char * labelNameStr = (itemVec[i]+"Label").c_str(); pLabel->setPosition(ScriptParser::getPositionFromPlist(plistDic,labelNameStr)); this->addChild(pLabel, zNum); } m_highlightSp->setPosition(ccp(mainitemSprite->getPosition().x,pTabBar->getPosition().y+pTabBar->getContentSize().height/2-50)); this->addChild(m_highlightSp,zNum); m_highlightSp->setColor(ccc3(200, 200, 200)); return true; }
QuestionMark::QuestionMark() { setTouchEnabled( true ); float scale = ScreenHelper::getTextureScale(); float scaleX = ScreenHelper::getTextureScaleX(); float scaleY = ScreenHelper::getTextureScaleY(); CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Buttons.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Buttons.plist"); CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Icons.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Icons.plist"); CCSprite *sprite = CCSprite::create("MainBackFiller.png"); sprite->setScaleX(scaleX*1.2f); sprite->setScaleY(scaleY*1.2f); sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,0.0f,-32.0f)); addChild(sprite); sprite = CCSprite::create("ctm_UI_topOverlayA_ver1.png"); sprite->setScaleX(scaleX); sprite->setScaleY(scaleY); sprite->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER)); addChild(sprite,2); CCLabelTTF *label = CCLabelTTF::create("?", "impact.ttf", 42*scale); addChild(label, 2); label->setColor(ccc3(0,0,0)); label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,2.0f,-52.0f)); label = CCLabelTTF::create("?", "impact.ttf", 42*scale); addChild(label, 2); label->setColor(ccc3(237,188,0)); label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-50.0f)); CCMenuItem *BackButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ctm_Back_Button.png"), CCSprite::createWithSpriteFrameName("ctm_Back_Button_Down.png"), this, menu_selector(QuestionMark::backButtonTapped)); BackButton->setScale(scale); BackButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_LEFT,50.0f,-50.0f)); CCMenu* menu = CCMenu::create(BackButton, NULL); menu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_BOTTOM_LEFT)); addChild(menu,4); CCSize dim; int randInt = RandomInt(0,100); if(randInt>95) { dim.width = 420*scale; dim.height = 250*scale; const char *colorText = "\"Surely you can't be serious!\" he says, as he slowly ambles back to his crimson hued overstuffed chair. You find yourself contemplating the simian who rebuffed your overture so out of hand. You can't help but admire this modern Grigori Rasputin for his steely determination. With perhaps undue influence of aqua vitae and plantains coloring your reason, you counter with tremendous vigor. With all the potency of Hannibal and his terrene leviathan you fill your hands with your own ordure and volley it squarely into his agape maw."; CCLabelTTF *text = CCLabelTTF::create(colorText,"impact.ttf",16*scale,dim,kCCTextAlignmentCenter); text->setColor(ccc3(230,230,230)); text->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER, 0.0f, -70.0f)); addChild(text); } else if(randInt>5) { int randomImage = RandomInt(1,14); CCTextureCache::sharedTextureCache()->addPVRImage("QuestionMark.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("QuestionMark.plist"); char temp[64]; sprintf(temp,"ConceptArt_%02d.png",randomImage); CCSprite *image = CCSprite::createWithSpriteFrameName(temp); image->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER, 0.0f, -35.0f)); image->setScale(0.5f*scale); addChild(image); } else { dim.width = 420*scale; dim.height = 250*scale; const char *colorText = "?"; CCLabelTTF *text = CCLabelTTF::create(colorText,"impact.ttf",80*scale,dim,kCCTextAlignmentCenter); text->setColor(ccc3(230,230,230)); text->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER, 0.0f, -70.0f)); addChild(text); } }
void GetPeanuts::BuildMenu() { float scale = ScreenHelper::getTextureScale(); float scaleX = ScreenHelper::getTextureScaleX(); float scaleY = ScreenHelper::getTextureScaleY(); CCMenu *screenMenu = CCMenu::create(); CCSize dim; dim.width = 200.0f; dim.height = 35.0f; for(int i = 0; i < 4; i++) { CCMenuItem *temp = CCMenuItemImage::create("ctm_Store_GrayStrip.png","ctm_Store_LitStrip.png","ctm_Store_LitStrip.png",this,menu_selector(GetPeanuts::buyButtonTapped) ); CCSprite *sprite = NULL; switch(i) { case 0: sprite = CCSprite::createWithSpriteFrameName("ctm_PeanutGraphic_A.png"); break; case 1: sprite = CCSprite::createWithSpriteFrameName("ctm_PeanutGraphic_B.png"); break; case 2: sprite = CCSprite::createWithSpriteFrameName("ctm_PeanutGraphic_C.png"); break; case 3: sprite = CCSprite::createWithSpriteFrameName("ctm_PeanutGraphic_D.png"); break; } sprite->setPosition(ccp(312/2-16,33)); temp->addChild(sprite); const char *amount; const char *cost; switch(i) { case 0: amount = "3,000"; cost = "$1.99"; break; case 1: amount = "35,000"; cost = "$7.99"; break; case 2: amount = "100,000"; cost = "$14.99"; break; case 3: amount = "300,000"; cost = "$24.99"; break; } CCLabelTTF *label = CCLabelTTF::create(amount,"Jacoby ICG Black.ttf",30,dim,kCCTextAlignmentRight); label->setColor(ccc3(237,188,0)); label->setPosition(ccp(200,46)); temp->addChild(label); CCSize dim; dim.width = 70.0f; dim.height = 20.0f; label = CCLabelTTF::create(cost,"Jacoby ICG Black.ttf",20,dim,kCCTextAlignmentRight); label->setColor(ccc3(230,230,230)); label->setPosition(ccp(260,23)); temp->addChild(label); temp->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,-250.0f,-i*50)); temp->setScale(scale); screenMenu->addChild(temp); m_MenuItems[i] = temp; } screenMenu->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,86,-119)); addChild(screenMenu); }
Credits::Credits() { setTouchEnabled( true ); float scale = ScreenHelper::getTextureScale(); float scaleX = ScreenHelper::getTextureScaleX(); float scaleY = ScreenHelper::getTextureScaleY(); CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Buttons.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Buttons.plist"); CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Icons.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Icons.plist"); CCSprite *sprite = CCSprite::create("MainBackFiller.png"); sprite->setScaleX(scaleX*1.2f); sprite->setScaleY(scaleY*1.2f); sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,0.0f,-32.0f)); addChild(sprite); sprite = CCSprite::create("ctm_UI_topOverlayA_ver1.png"); sprite->setScaleX(scaleX); sprite->setScaleY(scaleY); sprite->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER)); addChild(sprite,2); CCLabelTTF *label = CCLabelTTF::create("CREDITS", "impact.ttf", 42*scale); addChild(label, 2); label->setColor(ccc3(0,0,0)); label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,2.0f,-52.0f)); label = CCLabelTTF::create("CREDITS", "impact.ttf", 42*scale); addChild(label, 2); label->setColor(ccc3(237,188,0)); label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-50.0f)); sprite = CCSprite::create("box2d_logo2.png"); sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,0.0f,-10.0f)); sprite->setScale(0.75f*scale); addChild(sprite); sprite = CCSprite::create("*****@*****.**"); sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_RIGHT,-90.0f,-20.0f)); sprite->setScale(0.75f*scale); addChild(sprite); //////////////////////////////////////////////////// CCSize dim; dim.width = 300; dim.height = 50*scale; dim.width = 150*scale; CCLabelTTF *art = CCLabelTTF::create("Art","impact.ttf",20*scale,dim,kCCTextAlignmentLeft); art->setColor(ccc3(237,188,0)); art->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_LEFT,90.0f,40.0f)); addChild(art); CCLabelTTF *ken = CCLabelTTF::create("Ken Keys","impact.ttf",20*scale,dim,kCCTextAlignmentLeft); ken->setColor(ccc3(230,230,230)); ken->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_LEFT,90.0f,20.0f)); addChild(ken); CCLabelTTF *garrett = CCLabelTTF::create("Garrett Wren","impact.ttf",20*scale,dim,kCCTextAlignmentLeft); garrett->setColor(ccc3(230,230,230)); garrett->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_LEFT,90.0f,0.0f)); addChild(garrett); CCLabelTTF *programming = CCLabelTTF::create("Programming","impact.ttf",20*scale,dim,kCCTextAlignmentLeft); programming->setColor(ccc3(237,188,0)); programming->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_LEFT,90.0f,-35.0f)); addChild(programming); CCLabelTTF *ryan = CCLabelTTF::create("Ryan McBride","impact.ttf",20*scale,dim,kCCTextAlignmentLeft); ryan->setColor(ccc3(230,230,230)); ryan->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_LEFT,90.0f,-55.0f)); addChild(ryan); CCLabelTTF *audio = CCLabelTTF::create("Audio","impact.ttf",20*scale,dim,kCCTextAlignmentLeft); audio->setColor(ccc3(237,188,0)); audio->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_LEFT,90.0f,-85.0f)); addChild(audio); CCLabelTTF *pete = CCLabelTTF::create("Peter Lehman","impact.ttf",20*scale,dim,kCCTextAlignmentLeft); pete->setColor(ccc3(230,230,230)); pete->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_LEFT,90.0f,-105.0f)); addChild(pete); dim.width = 300*scale; CCLabelTTF *ludicrous = CCLabelTTF::create("© 2013 Ludicrous Games LLC","impact.ttf",24*scale,dim,kCCTextAlignmentRight); ludicrous->setAnchorPoint(ccp(1.0f,0.5f)); ludicrous->setColor(ccc3(237,188,0)); ludicrous->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_RIGHT,-15.0f,-95.0f)); addChild(ludicrous); CCMenuItem *BackButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ctm_Back_Button.png"), CCSprite::createWithSpriteFrameName("ctm_Back_Button_Down.png"), this, menu_selector(Credits::backButtonTapped)); BackButton->setScale(scale); BackButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_LEFT,50.0f,-50.0f)); CCMenu* menu = CCMenu::create(BackButton, NULL); menu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_BOTTOM_LEFT)); addChild(menu,4); }
Loading::Loading() { glClearColor(0.0f/255.0f, 0.0f/255.0f, 0.0f/255.0f, 1.0f); setTouchEnabled( true ); float scale = ScreenHelper::getTextureScale(); float scaleX = ScreenHelper::getTextureScaleX(); float scaleY = ScreenHelper::getTextureScaleY(); CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Buttons.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Buttons.plist"); CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Icons.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Icons.plist"); CCTextureCache::sharedTextureCache()->addPVRImage("LoadingScreen.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("LoadingScreen.plist"); CCPoint scalePoint; scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.y += -5*scale; CCSprite *sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_Screen_ver2.png"); sprite->setScale(scale); sprite->setPosition(scalePoint); addChild(sprite); sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_ProgressScroll_Graphic.png"); sprite->setScaleX(scaleX); sprite->setScaleY(scaleY*1.2f); sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_LEFT,-140.0f,-50.0f)); loadingBar = sprite; addChild(sprite,2); sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_TopPanel.png"); sprite->setScaleX(scaleX); sprite->setScaleY(scaleY); sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-55.0f)); addChild(sprite,2); sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_TopOverlay.png"); sprite->setScaleX(scaleX); sprite->setScaleY(scaleY); sprite->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER)); addChild(sprite,2); sprite = CCSprite::createWithSpriteFrameName("BackgroundPlate.png"); sprite->setScale(scale); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += -135.0f*scale; scalePoint.y += -97.0f*scale; sprite->setPosition(scalePoint); addChild(sprite,2); sprite = CCSprite::createWithSpriteFrameName("BronzeText.png"); sprite->setScale(scale); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += -135.0f*scale; scalePoint.y += -97.0f*scale; sprite->setPosition(scalePoint); addChild(sprite,2); CCLabelTTF *label = CCLabelTTF::create(LevelSelect::getLevelName(), "impact.ttf", 42*scale); addChild(label, 2); label->setColor(ccc3(0,0,0)); label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,2.0f,-44.0f)); label = CCLabelTTF::create(LevelSelect::getLevelName(), "impact.ttf", 42*scale); addChild(label, 2); label->setColor(ccc3(237,188,0)); label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-42.0f)); int currentLevel = LevelSelect::getCurrentLevel(); if(currentLevel >= BONUS_LEVELSTART) g_isTrickLevel = true; else g_isTrickLevel = false; int medalLevel = SaveLoad::m_SaveData.medalLockLevel; int showMedal = 0; if(medalLevel==0) { if(SaveLoad::m_SaveData.levelflags[currentLevel] & SaveLoad::ONE_COCONUT) showMedal = 1; } if(medalLevel==1) { if(SaveLoad::m_SaveData.levelflags[currentLevel] & SaveLoad::TWO_COCONUT) showMedal = 2; } if(medalLevel==2) { if(SaveLoad::m_SaveData.levelflags[currentLevel] & SaveLoad::THREE_COCONUT) showMedal = 3; } if(!showMedal) { CCSize dimensions; dimensions.width = 100*scale; dimensions.height = 25*scale; label = CCLabelTTF::create("Time:", "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(237,188,0)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+90.0f)*scale; scalePoint.y += 50.0f*scale; label->setPosition(scalePoint); char tempLabelStr[32]; sprintf(tempLabelStr,"%.2f",LevelSelect::getLevelGoals()->time); label = CCLabelTTF::create(tempLabelStr, "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(255,255,255)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+150.0f)*scale; scalePoint.y += 50.0f*scale; label->setPosition(scalePoint); label = CCLabelTTF::create("Peanuts:", "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(237,188,0)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+90.0f)*scale; scalePoint.y += 20.0f*scale; label->setPosition(scalePoint); sprintf(tempLabelStr,"%d",LevelSelect::getLevelGoals()->peanuts); label = CCLabelTTF::create(tempLabelStr, "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(255,255,255)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+170.0f)*scale; scalePoint.y += 20.0f*scale; label->setPosition(scalePoint); label = CCLabelTTF::create("Points:", "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(237,188,0)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+90.0f)*scale; scalePoint.y += -10.0f*scale; label->setPosition(scalePoint); sprintf(tempLabelStr,"%d",LevelSelect::getLevelGoals()->points); label = CCLabelTTF::create(tempLabelStr, "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(255,255,255)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+160.0f)*scale; scalePoint.y += -10.0f*scale; label->setPosition(scalePoint); } else { CCTextureCache::sharedTextureCache()->addPVRImage("LoadingScreen2.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("LoadingScreen2.plist"); if(showMedal == 1) sprite = CCSprite::createWithSpriteFrameName("ctm_BronzeMedalBig.png"); if(showMedal == 2) sprite = CCSprite::createWithSpriteFrameName("ctm_SilverMedalBig.png"); if(showMedal == 3) sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_LargeGold.png"); sprite->setScale(scale); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += -135.0f*scale; scalePoint.y += 5.0f*scale; sprite->setPosition(scalePoint); addChild(sprite,2); } CCMenuItem *StoreButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ctm_Button_17.png"), CCSprite::createWithSpriteFrameName("ctm_Button_17_Down.png"), this, menu_selector(Loading::storeButtonTapped)); StoreButton->setScale(scale); scalePoint = ccp(0,0); scalePoint.x += 85.0f*scale; scalePoint.y += -100.0f*scale; StoreButton->setPosition(scalePoint); CCMenu* menu = CCMenu::create(StoreButton, NULL); menu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER)); addChild(menu,4); CCMenuItemSprite *items[3]; //if(SaveLoad::m_SaveData.numDoubleNuts) { CCSize dim; dim.width = 200.0f; dim.height = 35.0f; CCSprite *barImage = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); CCSprite *barImageSel = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); barImage->setOpacity(0); barImageSel->setOpacity(0); CCMenuItemSprite *menuImage = CCMenuItemSprite::create(barImage,barImageSel,this,menu_selector(Loading::nutsButtonTapped)); CCLabelTTF *blabel = CCLabelTTF::create(" Use 2X Peanuts","Jacoby ICG Black.ttf",18,dim,kCCTextAlignmentLeft); blabel->setColor(ccc3(237,188,0)); blabel->setPosition(ccp(157.0f,18.0f)); menuImage->addChild(blabel,0,1234); items[1] = menuImage; CCSprite *sprite = CCSprite::createWithSpriteFrameName("ctm_icon_Store_17_2X-peanuts.png"); sprite->setPosition(ccp(30,23)); sprite->setScale(0.925f); menuImage->addChild(sprite,0,4321); menuImage->setScale(scale); if(!SaveLoad::m_SaveData.numDoubleNuts) { //[menuImage setIsEnabled:NO]; blabel->setColor(ccc3(237/2,188/2,0)); sprite->setColor(ccc3(128,128,128)); } } //if(SaveLoad::m_SaveData.numLevelFire) { CCSize dim; dim.width = 200.0f; dim.height = 35.0f; CCSprite *barImage = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); CCSprite *barImageSel = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); barImage->setOpacity(0); barImageSel->setOpacity(0); CCMenuItemSprite *menuImage = CCMenuItemSprite::create(barImage,barImageSel,this,menu_selector(Loading::fireButtonTapped)); CCLabelTTF *blabel = CCLabelTTF::create(" Use Permanent Fire","Jacoby ICG Black.ttf",18,dim,kCCTextAlignmentLeft); blabel->setColor(ccc3(237,188,0)); blabel->setPosition(ccp(157.0f,18.0f)); menuImage->addChild(blabel,0,1234); items[2] = menuImage; CCSprite *sprite = CCSprite::createWithSpriteFrameName("ctm_icon_Store_18_Fire.png"); sprite->setPosition(ccp(30,23)); sprite->setScale(0.925f); menuImage->addChild(sprite,0,4321); menuImage->setScale(scale); if(!SaveLoad::m_SaveData.numLevelFire) { //[menuImage setIsEnabled:NO]; blabel->setColor(ccc3(237/2,188/2,0)); sprite->setColor(ccc3(128,128,128)); } } //if(SaveLoad::m_SaveData.numTimeSlow) { CCSize dim; dim.width = 200.0f; dim.height = 35.0f; CCSprite *barImage = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); CCSprite *barImageSel = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); barImage->setOpacity(0); barImageSel->setOpacity(0); CCMenuItemSprite *menuImage = CCMenuItemSprite::create(barImage,barImageSel,this,menu_selector(Loading::timeButtonTapped)); CCLabelTTF *blabel = CCLabelTTF::create(" Use Slow Clock","Jacoby ICG Black.ttf",18,dim,kCCTextAlignmentLeft); blabel->setColor(ccc3(237,188,0)); blabel->setPosition(ccp(157.0f,18.0f)); menuImage->addChild(blabel,0,1234); items[0] = menuImage; CCSprite *sprite = CCSprite::createWithSpriteFrameName("ctm_icon_Store_16_Slow-Clock.png"); sprite->setPosition(ccp(30,23)); sprite->setScale(0.925f); menuImage->addChild(sprite,0,4321); menuImage->setScale(scale); if(!SaveLoad::m_SaveData.numTimeSlow) { //[menuImage setIsEnabled:NO]; blabel->setColor(ccc3(237/2,188/2,0)); sprite->setColor(ccc3(128,128,128)); } } CCMenu *powerUpMenu = CCMenu::create(items[0], items[1], items[2], NULL); powerUpMenu->alignItemsVerticallyWithPadding(-10.0); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += 100.0f*scale; scalePoint.y += 10.0f*scale; powerUpMenu->setPosition(scalePoint); addChild(powerUpMenu); m_TimeOut = 3.0f; scheduleUpdate(); }
bool HelpLayer::init(){ ////////////////////////////// // 1. super init first if (!CCLayer::init()){ return false; } CCScale9Sprite *pBackground = CCScale9Sprite::create("Dialog_bg.png"); pBackground->setAnchorPoint(ccp(0.5f,0.5f)); CCSize frameSize = CCEGLView::sharedOpenGLView()->getFrameSize(); float scale = frameSize.width / DESIGN_WIDTH; float newScaleY = 1.0f; if (scale > 0){ float scaleY = frameSize.height / DESIGN_HEIGHT; if (scaleY > scale){ newScaleY = scaleY / scale; } } pBackground->setPreferredSize(CCSizeMake(DESIGN_WIDTH - 20,(DESIGN_HEIGHT - 130) * newScaleY)); CCSize size = pBackground->getContentSize(); pBackground->setPosition(VisibleRect::center()); addChild(pBackground); CCSprite *pTitleBgSp = CCSprite::create("Dialog_Title.png"); pTitleBgSp->setPosition(ccp(pBackground->getPositionX(),pBackground->getPositionY() + pBackground->getContentSize().height / 2)); addChild(pTitleBgSp); CCSprite *pTitleSp = CCSprite::create("Title_Help.png"); pTitleSp->setPosition(ccp(pTitleBgSp->getPositionX(),pTitleBgSp->getPositionY() + pTitleSp->getContentSize().height / 2 + 5)); addChild(pTitleSp); CCSprite *pItemNormal = CCSprite::create("cancel_s.png"); CCSprite *pItemSelected = CCSprite::create("cancel_s.png"); CCMenuItem *pClose = CCMenuItemSprite::create(pItemNormal, pItemSelected, this, menu_selector(HelpLayer::close)); pClose->setPosition(ccp(pTitleSp->getPositionX() + pTitleSp->getContentSize().width * 3 / 2, pTitleSp->getPositionY())); pItemSelected->setScale(1.1f); pItemSelected->setAnchorPoint(ccp(0.05f, 0.05f)); CCMenu *pMenu = CCMenu::create(pClose, NULL); pMenu->setPosition(CCPointZero); addChild(pMenu, 1); CCDictionary *text = CCDictionary::createWithContentsOfFile(XML_DATA); CCString *msg = (CCString*)text->objectForKey("rule"); CCLabelTTF *msgLabel = CCLabelTTF::create(msg->getCString(), "Arial", 21,CCSizeMake(DESIGN_WIDTH - 40, 0),kCCTextAlignmentLeft); msgLabel->setColor(ccc3(0,0,0)); msgLabel->setPosition(ccp(pTitleBgSp->getPositionX(),pTitleBgSp->getPositionY() - pTitleBgSp->getContentSize().height / 2 - msgLabel->getContentSize().height / 2 - 5)); addChild(msgLabel); CCSprite *phSp = CCSprite::create("Help_1.png"); phSp->setPosition(ccp(msgLabel->getPositionX(),msgLabel->getPositionY() - msgLabel->getContentSize().height / 2 - phSp->getContentSize().height / 2 - 3)); addChild(phSp); msg = (CCString*)text->objectForKey("scoreTips"); msgLabel = CCLabelTTF::create(msg->getCString(), "Arial", 21,CCSizeMake(DESIGN_WIDTH - 40, 0),kCCTextAlignmentCenter); msgLabel->setColor(ccc3(0,0,0)); msgLabel->setPosition(ccp(phSp->getPositionX(),phSp->getPositionY() - phSp->getContentSize().height / 2 - msgLabel->getContentSize().height / 2 - 10)); addChild(msgLabel); phSp = CCSprite::create("Help_2.png"); phSp->setPosition(ccp(msgLabel->getPositionX(),msgLabel->getPositionY() - msgLabel->getContentSize().height / 2 - phSp->getContentSize().height / 2 - 3)); addChild(phSp); msg = (CCString*)text->objectForKey("pro"); msgLabel = CCLabelTTF::create(msg->getCString(), "Arial", 21,CCSizeMake(DESIGN_WIDTH - 40, 0),kCCTextAlignmentLeft); msgLabel->setColor(ccc3(0,0,0)); msgLabel->setPosition(ccp(pBackground->getPositionX() - pBackground->getContentSize().width / 2 + msgLabel->getContentSize().width / 2 + 10, phSp->getPositionY() - phSp->getContentSize().height / 2 - msgLabel->getContentSize().height / 2 - 3)); addChild(msgLabel); CCSprite* bombSp = CCSprite::create("Props_Bomb.png"); bombSp->setPosition(ccp(pBackground->getPositionX() - pBackground->getContentSize().width / 2 + bombSp->getContentSize().width / 2 + 10, msgLabel->getPositionY() - msgLabel->getContentSize().height / 2 - bombSp->getContentSize().height / 2 - 3)); addChild(bombSp); msg = (CCString*)text->objectForKey("bomb"); msgLabel = CCLabelTTF::create(msg->getCString(), "Arial", 18,CCSizeMake(DESIGN_WIDTH - 40, 0),kCCTextAlignmentLeft); msgLabel->setColor(ccc3(0,0,0)); msgLabel->setPosition(ccp(bombSp->getPositionX() + bombSp->getContentSize().width / 2 + msgLabel->getContentSize().width / 2 + 5, bombSp->getPositionY() + 13)); addChild(msgLabel); msg = (CCString*)text->objectForKey("useCoin"); CCString *showUseString = CCString::createWithFormat(msg->getCString(),GameData::getInstance()->m_nBombUseCoin); CCLabelTTF *showUseLabel = CCLabelTTF::create(showUseString->getCString(), "Arial", 14,CCSizeMake(DESIGN_WIDTH - 40, 0),kCCTextAlignmentLeft); showUseLabel->setColor(ccc3(0,0,0)); showUseLabel->setPosition(ccp(bombSp->getPositionX() + bombSp->getContentSize().width / 2 + showUseLabel->getContentSize().width / 2 + 5, msgLabel->getPositionY() - msgLabel->getContentSize().height / 2 - showUseLabel->getContentSize().height / 2 - 2)); addChild(showUseLabel); CCSprite *paintSp = CCSprite::create("Props_Paint.png"); paintSp->setPosition(ccp(pBackground->getPositionX() - pBackground->getContentSize().width / 2 + paintSp->getContentSize().width / 2 + 10, bombSp->getPositionY() - bombSp->getContentSize().height / 2 - paintSp->getContentSize().height / 2 - 10)); addChild(paintSp); msg = (CCString*)text->objectForKey("shua"); msgLabel = CCLabelTTF::create(msg->getCString(), "Arial", 18,CCSizeMake(DESIGN_WIDTH - 40, 0),kCCTextAlignmentLeft); msgLabel->setColor(ccc3(0,0,0)); msgLabel->setPosition(ccp(paintSp->getPositionX() + paintSp->getContentSize().width / 2 + msgLabel->getContentSize().width / 2 + 5, paintSp->getPositionY() + 13)); addChild(msgLabel); msg = (CCString*)text->objectForKey("useCoin"); showUseString = CCString::createWithFormat(msg->getCString(),GameData::getInstance()->m_nPaintUseCoin); showUseLabel = CCLabelTTF::create(showUseString->getCString(), "Arial", 14,CCSizeMake(DESIGN_WIDTH - 40, 0),kCCTextAlignmentLeft); showUseLabel->setColor(ccc3(0,0,0)); showUseLabel->setPosition(ccp(paintSp->getPositionX() + paintSp->getContentSize().width / 2 + showUseLabel->getContentSize().width / 2 + 5, msgLabel->getPositionY() - msgLabel->getContentSize().height / 2 - showUseLabel->getContentSize().height / 2 - 2)); addChild(showUseLabel); CCSprite *rainSp = CCSprite::create("Props_Rainbow.png"); rainSp->setPosition(ccp(pBackground->getPositionX() - pBackground->getContentSize().width / 2 + rainSp->getContentSize().width / 2 + 10, paintSp->getPositionY() - paintSp->getContentSize().height / 2 - rainSp->getContentSize().height / 2 - 10)); addChild(rainSp); msg = (CCString*)text->objectForKey("zhuan"); msgLabel = CCLabelTTF::create(msg->getCString(), "Arial", 18,CCSizeMake(DESIGN_WIDTH - 40, 0),kCCTextAlignmentLeft); msgLabel->setColor(ccc3(0,0,0)); msgLabel->setPosition(ccp(rainSp->getPositionX() + rainSp->getContentSize().width / 2 + msgLabel->getContentSize().width / 2 + 5, rainSp->getPositionY() + 13)); addChild(msgLabel); msg = (CCString*)text->objectForKey("useCoin"); showUseString = CCString::createWithFormat(msg->getCString(),GameData::getInstance()->m_nReflashUseCoin); showUseLabel = CCLabelTTF::create(showUseString->getCString(), "Arial", 14,CCSizeMake(DESIGN_WIDTH - 40, 0),kCCTextAlignmentLeft); showUseLabel->setColor(ccc3(0,0,0)); showUseLabel->setPosition(ccp(rainSp->getPositionX() + rainSp->getContentSize().width / 2 + showUseLabel->getContentSize().width / 2 + 5, msgLabel->getPositionY() - msgLabel->getContentSize().height / 2 - showUseLabel->getContentSize().height / 2 - 2)); addChild(showUseLabel); msg = (CCString*)text->objectForKey("quese"); msgLabel = CCLabelTTF::create(msg->getCString(), "Arial", 21,CCSizeMake(DESIGN_WIDTH - 40, 0),kCCTextAlignmentLeft); msgLabel->setColor(ccc3(0,0,0)); msgLabel->setPosition(ccp(pBackground->getPositionX() - pBackground->getContentSize().width / 2 + msgLabel->getContentSize().width / 2 + 10, rainSp->getPositionY() - rainSp->getContentSize().height / 2 - 25)); addChild(msgLabel); msg = (CCString*)text->objectForKey("phone"); showUseLabel = CCLabelTTF::create(msg->getCString(), "Arial", 21,CCSizeMake(DESIGN_WIDTH - 40, 0),kCCTextAlignmentLeft); showUseLabel->setColor(ccc3(0,0,0)); showUseLabel->setPosition(ccp(pBackground->getPositionX() - pBackground->getContentSize().width / 2 + showUseLabel->getContentSize().width / 2 + 10, msgLabel->getPositionY() - msgLabel->getContentSize().height / 2 - showUseLabel->getContentSize().height / 2 - 2)); addChild(showUseLabel); msg = (CCString*)text->objectForKey("qq"); msgLabel = CCLabelTTF::create(msg->getCString(), "Arial", 21,CCSizeMake(DESIGN_WIDTH - 40, 0),kCCTextAlignmentLeft); msgLabel->setColor(ccc3(0,0,0)); msgLabel->setPosition(ccp(pBackground->getPositionX() - pBackground->getContentSize().width / 2 + msgLabel->getContentSize().width / 2 + 10, showUseLabel->getPositionY() - showUseLabel->getContentSize().height / 2 - msgLabel->getContentSize().height / 2 - 2)); addChild(msgLabel); setPosition(ccp(0, -0.5 * getContentSize().height)); return true; }
bool GameSceneLayer::init(){ bool bRet = false; do{ CC_BREAK_IF(!CCLayer::init()); setKeypadEnabled(true); //CCLOG("init1"); //创建物理世界 b2Vec2 gravity; gravity.Set(0.0f,-10.0f); m_pMyworld = new b2World(gravity); m_pMyworld->SetAllowSleeping(true); m_pMyContactListener = new MyContactListener(); m_pMyworld->SetContactListener(m_pMyContactListener); //m_pDebugDraw = new GLESDebugDraw( PT_RATIO ); //m_pMyworld->SetDebugDraw(m_pDebugDraw); //uint32 flags = 0; //flags += b2Draw::e_shapeBit; //flags += b2Draw::e_jointBit; //flags += b2Draw::e_aabbBit; //flags += b2Draw::e_pairBit; //flags += b2Draw::e_centerOfMassBit; //m_pDebugDraw->SetFlags(flags); //创建一个地面 //b2BodyDef groundboxDef; ////groundboxDef. //b2Body *groundBody = m_pMyworld->CreateBody(&groundboxDef); //b2EdgeShape groundbox; ////groundbox.m_type //groundbox.Set(b2Vec2(0,220/32),b2Vec2(640.0f/32,220/32)); //groundBody->CreateFixture(&groundbox,0); //groundbox.Set(b2Vec2(0,0/32),b2Vec2(0,480.0f/32)); //groundBody->CreateFixture(&groundbox,0); //groundbox.Set(b2Vec2(640.0f/32,0/32),b2Vec2(640.0f/32,480.0f/32)); //groundBody->CreateFixture(&groundbox,0); //groundbox.Set(b2Vec2(0,480.0f/32),b2Vec2(640.0f/32,480.0f/32)); //groundBody->CreateFixture(&groundbox,0); //创建几个动态刚体 //for (int i = 0; i < 4; i++){ // CCSprite *sprite = CCSprite::create("image 277.png"); // sprite->setPosition(ccp(200+100*i,200)); // addChild(sprite); // addBoxbodyFromSprite(sprite); // //b2BodyDef bodydef; // //bodydef.type = b2_dynamicBody; // //bodydef.position.Set(200/32+100/32*i,200/32); // //b2Body *body = m_pMyworld->CreateBody(&bodydef); // //b2PolygonShape dynamicbox; // //dynamicbox.SetAsBox(0.5f,0.5f); // //b2FixtureDef fixturedef; // //fixturedef.shape = &dynamicbox; // //fixturedef.density = 1.0f; // //fixturedef.friction = 0.3f; // //fixturedef.restitution = 0.5f; // //body->CreateFixture(&fixturedef); //} //init CCSprite* bg; if (Setting::g_icurrentGate < 10) { bg = CCSprite::create("gamebg_1.png"); }else { bg = CCSprite::create("gamebg_2.png"); } bg->setPosition(ccp(Setting::g_ResolusionWidth/2,Setting::g_ResolusionHeight/2)); addChild(bg,-1); m_bDrawlineFlag = false; m_LineEndpos = m_LineStartpos = ccp(105,155); m_iResuduoMonsterNum = 0; //CCLOG("init2"); initTiledMap(); //添加一个炮台 CCSprite*cannonSprite = CCSprite::createWithSpriteFrameName("cannon.png"); addChild(cannonSprite,1); cannonSprite->setPosition(ccp(105,155)); cannonSprite->setTag(m_iCannonSpriteTag); CCSprite*batterySprite = CCSprite::createWithSpriteFrameName("battery.png"); addChild(batterySprite,1); batterySprite->setPosition(ccp(100,140)); batterySprite->setTag(m_iBatterySpriteTag); CCAnimation *pCannonAnimation = CCAnimation::create(); CCSpriteFrameCache *framecache = CCSpriteFrameCache::sharedSpriteFrameCache(); for(int i = 0 ; i < 5 ; i++){ pCannonAnimation->addSpriteFrame(framecache->spriteFrameByName(CCString::createWithFormat("cannon%d.png",i+1)->getCString())); } pCannonAnimation->setDelayPerUnit(0.08f); pCannonAnimation->setRestoreOriginalFrame(true); m_pCannonAnimate = CCAnimate::create(pCannonAnimation); m_pCannonAnimate->retain(); m_pCannonAnimate->setTag(m_iCannonAnimateTag); CCAnimation *pBatteryAnimation = CCAnimation::create(); for (int i = 0 ; i < 3 ; i++) { pBatteryAnimation->addSpriteFrame(framecache->spriteFrameByName(CCString::createWithFormat("battery%d.png",i+1)->getCString())); } pBatteryAnimation->setDelayPerUnit(0.08f); pBatteryAnimation->setRestoreOriginalFrame(true); m_pBatteryAnimate = CCAnimate::create(pBatteryAnimation); m_pBatteryAnimate->retain(); CCMenuItem* menuItem = CCMenuItemImage::create("button/btn_pause.png","button/btn_pause.png",this,menu_selector(GameSceneLayer::onPause)); menuItem->setPosition(ccp(60,460)); menuItem->setScale(0.5f,0.5f); CCMenu* menu = CCMenu::create(menuItem,NULL); menu->setPosition(ccp(0,0)); menu->setAnchorPoint(ccp(0,0)); this->addChild(menu,10); schedule(schedule_selector(GameSceneLayer::tick)); bRet = true; } while (0); return bRet; }
bool EndMenu::init() { if (!CCLayer::init()) { return false; } endMenuBg = CCSprite::create("UI/EndMenu/endMenuBg.png"); endMenuBg->setPosition(ccp(winSize.width/2 , winSize.height/2)); this->addChild(endMenuBg); CCMenuItem *retryButton = CCMenuItemImage::create("UI/EndMenu/retryButton.png", "UI/EndMenu/retryButton.png", this, menu_selector(EndMenu::RestartGame)); retryButton->setPosition(ccp(endMenuBg->getContentSize().width/2 - retryButton->getContentSize().width , endMenuBg->getContentSize().height/2 - retryButton->getContentSize().height)); CCMenuItem *backToMainButton = CCMenuItemImage::create("UI/EndMenu/mainMenuButton.png", "UI/EndMenu/mainMenuButton.png", this, menu_selector(EndMenu::GoToMainMenu)); backToMainButton->setPosition(ccp(endMenuBg->getContentSize().width/2 + retryButton->getContentSize().width , retryButton->getPosition().y)); CCArray *buttons = CCArray::create(retryButton , backToMainButton , NULL); CCMenu *theMenu = CCMenu::createWithArray(buttons); theMenu->setPosition(CCPointZero); endMenuBg->addChild(theMenu); distanceLabel = CCLabelTTF::create("0", GAME_FONT.c_str(), 35); distanceLabel->setHorizontalAlignment(kCCTextAlignmentLeft); distanceLabel->setPosition(ccp(endMenuBg->getContentSize().width/2 , endMenuBg->getContentSize().height * 0.71f)); endMenuBg->addChild(distanceLabel); mushroomLabel = CCLabelTTF::create("0", GAME_FONT.c_str(), 35); mushroomLabel->setHorizontalAlignment(kCCTextAlignmentLeft); mushroomLabel->setAnchorPoint(ccp(0 , 0.5f)); mushroomLabel->setPosition(ccp(endMenuBg->getContentSize().width * 0.60f , endMenuBg->getContentSize().height * 0.62f)); endMenuBg->addChild(mushroomLabel); bonusRoundLabel = CCLabelTTF::create("0", GAME_FONT.c_str(), 35); bonusRoundLabel->setHorizontalAlignment(kCCTextAlignmentLeft); bonusRoundLabel->setAnchorPoint(ccp(0 , 0.5f)); bonusRoundLabel->setPosition(ccp(mushroomLabel->getPosition().x + mushroomLabel->getContentSize().width*2 , mushroomLabel->getPosition().y)); endMenuBg->addChild(bonusRoundLabel); mushroomIcon = CCSprite::create("Collectable/mushroom.png"); mushroomIcon->setPosition(ccp(endMenuBg->getContentSize().width * 0.3f , mushroomIcon->getContentSize().height)); endMenuBg->addChild(mushroomIcon , 5); char fn[64]; sprintf(fn , "%d" , totalCoins); totalMushroomLabel = CCLabelTTF::create(fn, GAME_FONT.c_str(), 30); totalMushroomLabel->setAnchorPoint(ccp(0 , 0.5f)); totalMushroomLabel->setPosition(ccp(mushroomIcon->getPosition().x + mushroomIcon->getContentSize().width , mushroomIcon->getPosition().y)); endMenuBg->addChild(totalMushroomLabel , 5); return true; }
// initialize your instance here Store::Store() { //SaveLoad::m_SaveData.currency = 300000; //SaveLoad::SaveGame(); // enable touches setTouchEnabled( true ); float scale = ScreenHelper::getTextureScale(); float scaleX = ScreenHelper::getTextureScaleX(); float scaleY = ScreenHelper::getTextureScaleY(); CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Buttons.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Buttons.plist"); CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Icons.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Icons.plist"); CCSprite *sprite = CCSprite::create("MainBackFiller.png"); sprite->setScaleX(scaleX*1.2f); sprite->setScaleY(scaleY*1.2f); sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,0.0f,-32.0f)); addChild(sprite); sprite = CCSprite::create("ctm_UI_topOverlayA_ver1.png"); sprite->setScaleX(scaleX); sprite->setScaleY(scaleY); sprite->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER)); addChild(sprite,2); CCLabelTTF *label = CCLabelTTF::create("STORE", "impact.ttf", 42*scale); addChild(label, 2); label->setColor(ccc3(0,0,0)); label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,2.0f,-52.0f)); label = CCLabelTTF::create("STORE", "impact.ttf", 42*scale); addChild(label, 2); label->setColor(ccc3(237,188,0)); label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-50.0f)); CCMenuItem *BackButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ctm_Back_Button.png"), CCSprite::createWithSpriteFrameName("ctm_Back_Button_Down.png"), this, menu_selector(Store::backButtonTapped)); BackButton->setScale(scale); BackButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_LEFT,50.0f,-50.0f)); ReturnButton = BackButton; CCSprite *spritePeanut = CCSprite::createWithSpriteFrameName("ctm_UI_Peanuts_Btn_ver1.png"); CCSprite *spritePeanutDown = CCSprite::createWithSpriteFrameName("ctm_UI_Peanuts_Btn_Down.png"); sprite = CCSprite::createWithSpriteFrameName("ctm_UI_PeanutsGlow_Btn_ver1.png"); sprite->setPosition(ccp(136/2, 104/2)); spritePeanut->addChild(sprite); CCMenuItem *PeanutsButton = CCMenuItemSprite::create(spritePeanut,spritePeanutDown,this,menu_selector(Store::peanutButtonTapped)); PeanutsButton->setScale(scale); PeanutsButton->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT,90.0f,130.0f)); CCMenu* backmenu = CCMenu::create(BackButton, NULL); backmenu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_BOTTOM_LEFT)); addChild(backmenu,4); m_slideControl = CCNode::create(); addChild(m_slideControl); CCMenu* peanutmenu = CCMenu::create(PeanutsButton, NULL); peanutmenu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_BOTTOM_LEFT)); m_slideControl->addChild(peanutmenu,4); CCScrollingMenu *screenMenu = CCScrollingMenu::create(); screenMenu->setPosition(0,0); BuildUpgrades(screenMenu); BuildPowerUps(screenMenu); BuildCharacters(screenMenu); BuildBikes(screenMenu); screenMenu->alignItemsVerticallyWithPadding(-10*scaleY); CCSize viewSize; viewSize.width = 320.0f*scaleX; viewSize.height = 1450.0f*scaleY/(scaleY/scale); CCScrollView *scrollView = CCScrollView::create(viewSize,screenMenu); //scrollView->setBounceable(false); //temp = ComingSoonButton->getPositionX()/scaleX-480.0f; //temp += (ComingSoonButton->getContentSize().width)/scale; scrollView->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT,160,275.0f*(scaleY/scale)-(viewSize.height/((scaleY+scale)/2.0f))/2.0f)); scrollView->setContentSize(screenMenu->getContentSize()); scrollView->setContentOffset(ccp(312.0f/2.0f*scaleX,0.0f)); scrollView->setDirection(kCCScrollViewDirectionVertical); m_slideControl->addChild(scrollView); char currencyStr[32]; sprintf(currencyStr,"$%d",SaveLoad::m_SaveData.currency); CCSize dim; dim.width = 100.0f; dim.height = 25.0f; m_currency = CCLabelBMFont::create(currencyStr,"JacobyICGBlack22pnt.fnt"); m_currency->setScale(scale); m_currency->setAnchorPoint(ccp(1.0f,0.5f)); m_currency->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_BOTTOM_LEFT,456, 238)); addChild(m_currency,10); if(SaveLoad::m_SaveData.beenToStore==0) { SaveLoad::m_SaveData.beenToStore=1; SaveLoad::Save(); // [TestFlight passCheckpoint:@"STORE_VISIT"]; } scheduleUpdate(); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object // CCMenuItemImage *pCloseItem = CCMenuItemImage::create( // "CloseNormal.png", // "CloseSelected.png", // this, // menu_selector(HelloWorld::menuCloseCallback)); // //pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , // origin.y + pCloseItem->getContentSize().height/2)); // // create menu, it's an autorelease object // CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); // pMenu->setPosition(CCPointZero); // this->addChild(pMenu, 1); // ///////////////////////////// // // 3. add your codes below... // // add a label shows "Hello World" // // create and initialize a label // // CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24); // // // position the label on the center of the screen // pLabel->setPosition(ccp(origin.x + visibleSize.width/2, // origin.y + visibleSize.height - pLabel->getContentSize().height)); // // add the label as a child to this layer // this->addChild(pLabel, 1); // add "HelloWorld" splash screen" CCSprite* pSprite = CCSprite::create("HelloWorld.png"); // position the sprite on the center of the screen pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(pSprite, 0); //CCSprite* pSprite = CCSprite::create("HelloWorld.png"); // // position the sprite on the center of the screen // pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // // add the sprite as a child to this layer // this->addChild(pSprite, 0); /*CCMenuItemLabel* labTtf = CCMenuItemLabel::create(CCLabelTTF::create("lable Menu Test","Arial",20),this,menu_selector(HelloWorld::clickImage)); labTtf->setPosition(ccp(visibleSize.width/2,visibleSize.height/10)); CCMenu *pMenuLabl = CCMenu::create(labTtf,NULL); pMenuLabl->setPosition(CCPointZero); this->addChild(pMenuLabl,1);*/ CCMenuItem *pImage = CCMenuItemImage::create("CloseNormal.png","CloseSelected.png",this,menu_selector(HelloWorld::clickImage)); pImage->setPosition(visibleSize.width - pImage->getContentSize().width/2,visibleSize.height/2); CCMenu *pMenu = CCMenu::create(pImage,NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu,1); return true; }