bool HeadUpDisplay::init(){ if(!CCMenu::init()) return false; /* Adding a "close" button to exit. */ CCMenuItemImage *pCloseItem = CCMenuItemImage::create("CloseNormal.png", "CloseSelected.png", this, menu_selector(HeadUpDisplay::menuCloseCallback)); CCSize scrSize = CCDirector::sharedDirector()->getWinSize(); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); pCloseItem->setPosition( ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); this->addChild(pCloseItem,1); /* Mesh */ CCSprite* mesh = CCSprite::create(); mesh->setTextureRect(CCRect(0,0,scrSize.width,scrSize.height)); mesh->setColor(ccc3(0,0,0)); mesh->setOpacity(0); mesh->setAnchorPoint(ccp(0,0)); mesh->setPosition(CCPointZero); mesh->setTag(_meshTag); this->addChild(mesh,0); /* Bubble Talk */ CCSprite* bubble = CCSprite::create("bubbleTalk.png"); CCPoint bblePos = scrSize/2; bubble->setPosition(bblePos); bubble->setScale(0); bubble->setTag(_bubbleTalkTag); this->addChild(bubble,0); /* Message */ CCLabelTTF* labelMsg = CCLabelTTF::create("Bonjour!\n :)","Artial", 32); CCSize bubbleSize = bubble->getContentSize(); labelMsg->setPosition(bubbleSize/2); labelMsg->setOpacity(0); labelMsg->setTag(_messageTag); bubble->addChild(labelMsg,0); /* Accept Button */ CCMenuItemImage* acceptButton = CCMenuItemImage::create( "acceptButton.png","acceptButtonPressed.png", this, menu_selector(HeadUpDisplay::hideMessage)); acceptButton->retain(); CCSize aBtnSize = acceptButton->getContentSize(); acceptButton->setPosition(ccp( bblePos.x + bubbleSize.width/2 - aBtnSize.width * .25f, bblePos.y - bubbleSize.height/2 + aBtnSize.height * .25f)); acceptButton->setVisible(false); this->addChild(acceptButton,0,_acceptButtonTag); this->setPosition(CCPointZero); return true; }
void Study1::initWords() { if (this->strWords.size() == 0) { return; } CCPoint wordPoint[6] = { ccp(296,110), ccp(383,110), ccp(466,110), ccp(552,110), ccp(636,110), ccp(720,110),}; CCMenu* pMenu = CCMenu::create(); pMenu->setPosition( CCPointZero ); addChild(pMenu); char str[100]; for (int i=0; i<strWords.size(); i++) { CCMenuItemImage *pi = CCMenuItemImage::create( "wkszStudy1/wordbg1.png", "wkszStudy1/wordbg2.png", this, menu_selector(Study1::wordCB) ); if (i == 0) { CCNode *img = CCSprite::createWithTexture(CCTextureCache::sharedTextureCache()->textureForKey("wkszStudy1/wordbg3.png")); pi->setNormalImage(img); } pi->setPosition(wordPoint[i%PAGE_CAPACITY]); pi->setTag(i); pi->setVisible(false); menuWords.push_back(pi); pMenu->addChild(pi); CCLOG("str:%s",strWords[i].c_str()); CCLabelTTF* pLabel = CCLabelTTF::create(strWords[i].c_str(), "Thonburi", 34); pLabel->setPosition( ccp(297+i%PAGE_CAPACITY*85,112) ); pLabel->setColor(ccBLACK); pLabel->setVisible(false); labelWords.push_back(pLabel); this->addChild(pLabel, 9); sprintf(str, "wkszCharacter1/%s.swf",strWords[i].c_str()); CCSWFNode* swf1 = CCSWFNode::create(str); swf1->setPosition(ccp(506,445)); // swf1->setScale(0.8f); // swf1->runAction(); swf1->setRepeat(true); swf1->setVisible(false); swfWords1.push_back(swf1); this->addChild(swf1,9); sprintf(str, "wkszCharacter2/%s.swf",strWords[i].c_str()); CCSWFNode* swf2 = CCSWFNode::create(str); swf2->setPosition(ccp(280,243)); // swf2->setScale(0.8f); // swf2->runAction(); swf2->setRepeat(true); swf2->setVisible(false); swfWords2.push_back(swf2); this->addChild(swf2,9); } }
TanSuoLayer::TanSuoLayer() { m_nFontSize = 24; m_nMaxCountDestroy = 3; m_bIsJieFeng = false; m_nSelectProId = -1; mBg = BaseSprite::create("xunbao_bg.png"); addChild(mBg); mBg->setPosition(ccp(mWinSize.width/2, mBg->getContentSize().height/2)); mMainMenu = CCMenu::create(); mBg->addChild(mMainMenu, 10); mMainMenu->setPosition(ccp(0,0)); CCMenuItemImage *yijian = CCMenuItemImage::create( "xunbao_anniu_yijianxunbao.png", "xunbao_anniu_yijianxunbao_select.png", this, menu_selector(TanSuoLayer::menuItemClicked_TanSuo)); mMainMenu->addChild(yijian, 0, Tag_MenuItem_YiJianTanSuo); yijian->setPosition(ccp(548,mBg->getContentSize().height-674)); Button *tansuo = Button::create(); tansuo->loadTextures("xunbao_anniu_xunbao.png","xunbao_anniu_xunbao_select.png","xunbao_anniu_xunbao_select.png",UI_TEX_TYPE_LOCAL); /*CCMenuItemImage *tansuo = CCMenuItemImage::create( "xunbao_anniu_xunbao.png", "xunbao_anniu_xunbao_select.png", this, menu_selector(TanSuoLayer::menuItemClicked_TanSuo));*/ tansuo->addTouchEventListener(this,SEL_TouchEvent(&TanSuoLayer::clickXunBao)); UILayer* layer = UILayer::create(); layer->ignoreAnchorPointForPosition(false); layer->setContentSize(tansuo->getContentSize()); layer->setAnchorPoint(ccp(0.5,0.5)); layer->addWidget(tansuo); layer->setPosition(320,mBg->getContentSize().height-674);//以前cpp(x,y) 现在左边 都是Point 比如颜色 ccWHITE 也改成了Color3B::WHITE mBg->addChild(layer); tansuo->setPosition(ccp(tansuo->getContentSize().width / 2 , tansuo->getContentSize().height / 2)); m_sXunBaoSpr = CCSprite::create("xunbao_anniu_xunbao_xiaoguo.png"); m_sXunBaoSpr->setPosition(ccp(320,mBg->getContentSize().height-674)); mBg->addChild(m_sXunBaoSpr); m_sXunBaoSpr->runAction(CCRepeatForever::create(CCSequence::create(CCFadeOut::create(1.0f),CCFadeIn::create(1.0f),NULL))); //mMainMenu->addChild(tansuo, 0, Tag_MenuItem_TanSuo); //tansuo->setPosition(ccp(320,mBg->getContentSize().height-674)); { CCMenuItemImage *jiefen = CCMenuItemImage::create( "xunbao_anniu_jiechufengyin.png", "xunbao_anniu_jiechufengyin_select.png", this, menu_selector(TanSuoLayer::menuItemClicked_TanSuo)); mMainMenu->addChild(jiefen, 0, Tag_MenuItem_JieFen); jiefen->setPosition(ccp(320,mBg->getContentSize().height-437)); jiefen->setVisible(false); CCSprite *img = CCSprite::create("xunbao_anniu_jiechufengyin_xiaoguo.png"); jiefen->addChild(img); img->setPosition(ccp(jiefen->getContentSize().width/2, jiefen->getContentSize().height/2)); img->runAction(CCRepeatForever::create(CCSequence::create( CCFadeTo::create(1, 50), CCFadeTo::create(1, 255), NULL))); } mMainMenu->setVisible(false); //title CCLabelTTF *tilte = CCLabelTTF::create(LFStrings::getValue("XunBaoShuoMing").c_str(), fontStr_kaiti, m_nFontSize); mBg->addChild(tilte); tilte->setColor(fonColor_PuTong); tilte->setPosition(ccp(mBg->getContentSize().width/2, mBg->getContentSize().height-110)); //2 CCLabelTTF *la1 = CCLabelTTF::create(LFStrings::getValue("XunBaoJieFeng").c_str(), fontStr_kaiti, m_nFontSize); mBg->addChild(la1); la1->setAnchorPoint(ccp(0, 0.5)); la1->setColor(fonColor_CiYao); la1->setPosition(ccp(134, mBg->getContentSize().height-140)); CCLabelTTF *la2 = CCLabelTTF::create((LFStrings::getValue("shenbing")+LFStrings::getValue("zhuangbei")).c_str() , fontStr_kaiti, m_nFontSize); la1->addChild(la2); la2->setColor(ImageManager::getManager()->getShowColor(ZhuangbeiColour_Chuanqi, false, false)); la2->setPosition(ccp(la1->getContentSize().width+la2->getContentSize().width/2, la1->getContentSize().height/2)); la1->setPositionX((mBg->getContentSize().width-la1->getContentSize().width-la2->getContentSize().width)/2); }
bool GameWorld::init() { do { CC_BREAK_IF(! CCLayer::init()); CCMenuItemImage *pTransform = CCMenuItemImage::create( "6.png", "6.png", this, menu_selector(GameWorld::menuTransformCallback)); CCMenuItemImage *pLeft = CCMenuItemImage::create( "6.png", "6.png", this, menu_selector(GameWorld::menuLeftCallback)); CCMenuItemImage *pRight = CCMenuItemImage::create( "6.png", "6.png", this, menu_selector(GameWorld::menuRightCallback)); CCMenuItemImage *pDown = CCMenuItemImage::create( "6.png", "6.png", this, menu_selector(GameWorld::menuDownCallback)); CCMenuItemImage *pGameOver = CCMenuItemImage::create( "GameOver.jpg", "GameOver.jpg", this, menu_selector(GameWorld::menuGameOver)); // Place the menu item bottom-right conner. CCSize size = CCDirector::sharedDirector()->getWinSize(); pTransform->setPosition(ccp(size.width - 190, 210)); pLeft->setPosition(ccp(size.width - 260, 140)); pRight->setPosition(ccp(size.width - 120, 140)); pDown->setPosition(ccp(size.width - 190, 70)); pGameOver->setPosition(ccp(size.width / 2, size.height / 2)); pGameOver->setScale(5); pGameOver->setVisible(false); mMenuGameOver = pGameOver; // Create a menu with the "close" menu item, it's an auto release object. CCMenu* pMenu = CCMenu::create(pTransform, pLeft, pRight, pDown, pGameOver, NULL); pMenu->setPosition(CCPointZero); CC_BREAK_IF(! pMenu); addChild(pMenu, 1); CCDrawNode *pDrawNode = CCDrawNode::create(); addChild(pDrawNode); CCPoint points[] = { CCPoint(0,0), CCPoint((CubeManager::MAIN_BOARD_WIDTH)* CubeManager::CUBE_SIZE, 0), CCPoint((CubeManager::MAIN_BOARD_WIDTH)* CubeManager::CUBE_SIZE, (CubeManager::MAIN_BOARD_HEIGHT + 1)* CubeManager::CUBE_SIZE), CCPoint(0, (CubeManager::MAIN_BOARD_HEIGHT + 1)* CubeManager::CUBE_SIZE) }; pDrawNode->drawPolygon(points, sizeof(points)/sizeof(points[0]), ccc4f(0,0,0.3f,0.5f), 4, ccc4f(0,0,1,1)); CCLabelTTF* pLabel = CCLabelTTF::create("Score:", "Arial", 56); pLabel->setPosition(ccp(size.width - 300, 1100)); pLabel->setAnchorPoint(ccp(0, 0.5f)); this->addChild(pLabel); pLabel = CCLabelTTF::create("0", "Arial", 56); pLabel->setPosition(ccp(size.width - 300, 1000)); pLabel->setColor(ccc3(255, 192, 0)); pLabel->setAnchorPoint(ccp(0, 0.5f)); //pLabel->setHorizontalAlignment(kCCTextAlignmentRight); this->addChild(pLabel); mLabelScore = pLabel; if (!mCubeManager.init(this)) return false; schedule(schedule_selector(GameWorld::stepGo), 0.5f); schedule(schedule_selector(GameWorld::checkKeyInput)); schedule(schedule_selector(GameWorld::onKeyInput), 0.05f); } while(0); return true; }
CCSprite* IOSStoreLayer::createCellSpr(int index, CellInfo* daojuInfo) { CCSprite* pDaoju = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_storelayerPath+"main_shangdian_daoju_bg.png").c_str()); //显示道具的名字 CCLabelTTF* pTitle = CCLabelTTF::create(daojuInfo->nameStr.c_str(), fontStr_katong, 24); pDaoju->addChild(pTitle); pTitle->setColor(fontColor_Store); pTitle->setPosition(ccp(pDaoju->getContentSize().width/2, pDaoju->getContentSize().height - 40)); //显示道具的描述 CCLabelTTF* pDescribe = CCLabelTTF::create(daojuInfo->describeStr.c_str(), fontStr_katong, 24, CCSizeMake(200, 60), kCCTextAlignmentLeft); pDaoju->addChild(pDescribe); pDescribe->setAnchorPoint(ccp(0, 0.5f)); pDescribe->setHorizontalAlignment(kCCTextAlignmentLeft); pDescribe->setPosition(ccp(10, 85)); if (daojuInfo->bBaoxiang) { pDescribe->setPosition(ccp(10, 65)); } //显示图标 CCSprite* pIcon = CCSprite::create(daojuInfo->iconNameStr.c_str()); // if (pIcon) { pIcon->setPosition(ccp(pDaoju->getContentSize().width/2, pDaoju->getContentSize().height/2+20)); pDaoju->addChild(pIcon, 1); CCSprite *mask = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_storelayerPath+"main_shangdian_daoju_fugai.png").c_str()); pDaoju->addChild(mask, 2); mask->setPosition(ccp(pIcon->getPositionX(), pIcon->getPositionY()+20)); } //宝箱需要设置缩放为35% if (daojuInfo->bBaoxiang) { pIcon->setScale(0.35f); } //底部按钮 CCMenuItemImage* pMenuItem = CCMenuItemImage::create( daojuInfo->btnIconNorNameStr.c_str(), daojuInfo->btnIconSelNameStr.c_str(), this, menu_selector(IOSStoreLayer::menuBtnCallBack)); //星星数不够就显示文字,够的话就显示开宝箱按钮 if (pMenuItem) { bool bMore = false; int iStarCount = GameInforEditer::getGameInfor()->getTotalFreeScore(); if (daojuInfo->bBaoxiang) { if (daojuInfo->iBaoxiangCount == 10) { if (iStarCount >= 95) { bMore = true; } } else if (daojuInfo->iBaoxiangCount == 1) { if (iStarCount >= 10) { bMore = true; } } } else { bMore = true; } CCMenu* pMenu = CCMenu::create(); pMenu->setPosition(CCPointZero); pDaoju->addChild(pMenu, 1); pMenu->addChild(pMenuItem); pMenuItem->setPosition(ccp(pDaoju->getContentSize().width/2, pMenuItem->getContentSize().height/2)); pMenu->setTouchPriority(kCCMenuHandlerPriority-3); pMenuItem->setVisible(false); if (bMore) { pMenuItem->setVisible(true); } else if (daojuInfo->bBaoxiang) { //星星不足时,显示的字符串 CCLabelTTF* pTip = CCLabelTTF::create(LFStrings::getValue("Starless").c_str(), fontStr_katong, 24, CCSizeMake(200, 60), kCCTextAlignmentCenter); pDaoju->addChild(pTip,1); pTip->setPosition(ccp(pDaoju->getContentSize().width/2, pMenuItem->getContentSize().height/2+5)); } } //宝箱和购买星星区别加载 if (daojuInfo->bBaoxiang) { //十个宝箱 if (daojuInfo->iBaoxiangCount == 10) { pIcon = CCSprite::create(daojuInfo->iconBgNameStr.c_str()); if (pIcon) { pIcon->setPosition(ccp(pDaoju->getContentSize().width/2, pDaoju->getContentSize().height/2+20)); pDaoju->addChild(pIcon); pIcon->setScale(0.35f); } //十次 pMenuItem->setTag(tentimes_btn_tag); } else if (daojuInfo->iBaoxiangCount == 1) { //一次 pMenuItem->setTag(onetimes_btn_tag); } } else { //按照价格来设置购买按钮的tag pMenuItem->setTag(daojuInfo->iPrice); } return pDaoju; }
void IOSStoreLayer::showItemsNode() { int iTotalCount = 1; int iPrice = 10; int xcount = 1; int ycount = 1; CCSize size = CCSizeMake(120, 190); if (m_bBaoxiangBuyTenTimes) { iTotalCount = 10; size.width = 820; size.height = 350; xcount = 5; ycount = 2; iPrice = 95; } iTotalCount = this->getKaiBaoxiangRsqData().size(); if (iTotalCount >= 11) { xcount = 6; } if (iTotalCount == 2) { xcount = 2; size = CCSizeMake(140*2, 190); } IOSStoreLayerScrollView* pView = IOSStoreLayerScrollView::createView(size, iTotalCount, xcount, ycount); m_pGetItemNode->addChild(pView); pView->ignoreAnchorPointForPosition(false); pView->setAnchorPoint(ccp(0.5f, 0.5f)); pView->setPosition(ccp(this->getContentSize().width/2, this->getContentSize().height/2 - 60)); pView->setClickableCreater(pView); pView->prepareToDisplay(); pView->setTouchEnabled(false); pView->setTag(getitem_scrollview_tag); //显示 CCSprite* pSmallbg = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_storelayerPath+"main_shangdian_anniu_zaikaishici_fujia.png").c_str()); m_pGetItemNode->addChild(pSmallbg, 1); pSmallbg->setPosition(ccp(200, 100)); //添加菜单 CCMenu* pMenu = CCMenu::create(); pMenu->setPosition(CCPointZero); m_pGetItemNode->addChild(pMenu, 2); //再开按钮 CCMenuItemImage* pItem = NULL; int iStarCount = GameInforEditer::getGameInfor()->getTotalFreeScore(); if (m_bBaoxiangBuyTenTimes) { pItem = CCMenuItemImage::create( ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_zaikaishici.png").c_str(), ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_zaikaishici_select.png").c_str(), this, menu_selector(IOSStoreLayer::menuBtnCallBack)); pItem->setTag(buy_ten_again); } else { pItem = CCMenuItemImage::create( ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_zaikaiyici.png").c_str(), ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_zaikaiyici_select.png").c_str(), this, menu_selector(IOSStoreLayer::menuBtnCallBack)); pItem->setTag(buy_one_again); } pItem->setPosition(ccp(pSmallbg->getPositionX() + pSmallbg->getContentSize().width/2 + pItem->getContentSize().width/2 - 30, pSmallbg->getPositionY())); pMenu->addChild(pItem); //星星数量 CCLabelAtlas* lable = CCLabelAtlas::create( "0123456789", ResManager::getManager()->getSharedFilePath(g_seasonlayerPath+"season_star_amount.png").c_str(), 30, 47,//24 '0'); m_pGetItemNode->addChild(lable, 1, star_count_str_tag); lable->setAnchorPoint(ccp(0, 0.5)); lable->setScale(0.6f); int iCount = 10; if (m_bBaoxiangBuyTenTimes) { iCount = 95; } char charStarCount[10] = {}; sprintf(charStarCount, "%d", iCount); lable->setString(charStarCount); lable->setPosition(ccp(pItem->getPositionX()-pItem->getContentSize().width/2-lable->getContentSize().width/2 - 40, pSmallbg->getPositionY() - 3)); //右边星星图标 CCSprite* pXingxing = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_xiaogk+"YX_start.png").c_str()); m_pGetItemNode->addChild(pXingxing, 1); pXingxing->setPosition(ccp(lable->getPositionX() - 30, pSmallbg->getPositionY())); //星星数不够时,只显示确定按钮 //确定按钮 CCMenuItemImage* pOKItem = CCMenuItemImage::create( ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_quedingi.png").c_str(), ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_quedingi_select.png").c_str(), this, menu_selector(IOSStoreLayer::menuBtnCallBack)); pOKItem->setTag(ok_btn_tag); pOKItem->setPosition(ccp(this->getContentSize().width/2 + pOKItem->getContentSize().width, pSmallbg->getPositionY())); pMenu->addChild(pOKItem); if (iStarCount < iPrice) { lable->setVisible(false); pXingxing->setVisible(false); pSmallbg->setVisible(false); pItem->setVisible(false); pOKItem->setPosition(ccp(this->getContentSize().width/2, pSmallbg->getPositionY())); } pMenu->setTouchPriority(kCCMenuHandlerPriority-5); }
bool RankingScene::init() { CCSize size = CCDirector::sharedDirector()->getWinSize(); w = size.width; h = size.height; players = new CCArray(); CCSprite *background = CCSprite::create("BackGrounds/BackGround2.png"); background->setPosition(ccp(w/2, h/2)); this->addChild(background); CCSprite *topLine = CCSprite::create("line.png"); topLine->setPosition(ccp(w/2, 602)); topLine->setOpacity(70); this->addChild(topLine); CCSprite *bottomLine = CCSprite::create("line.png"); bottomLine->setPosition(ccp(w/2, 248)); bottomLine->setOpacity(70); this->addChild(bottomLine); //-------------- menu getperesent --------------- CCMenuItemImage *reward = CCMenuItemImage::create("Present.png","PresentOnClicked.png", this, menu_selector(RankingScene::reward)); reward->setPosition(ccp(w/5, h/8)); string playerName = GameManager::sharedGameManager()->getName(); if (playerName == "") reward->setVisible(false); CCHttpRequest* request = new CCHttpRequest(); string ipAddr = GameManager::sharedGameManager()->getIpAddr(); request->setUrl((ipAddr+":3000/users.json").c_str()); request->setRequestType(CCHttpRequest::kHttpGet); request->setResponseCallback(this, callfuncND_selector(RankingScene::onHttpRequestCompleted)); CCHttpClient::getInstance()->send(request); request->release(); //create startMenuItem CCMenuItemImage *playItem = CCMenuItemImage::create("Buttons/StartButton.png", "Buttons/StartButtonOnClicked.png", this, menu_selector(RankingScene::play)); playItem->setPosition(ccp(w/2, h/8 - 10)); //create bgmItem CCMenuItemImage *bgmItem = CCMenuItemImage::create("BgmOn.png", "BgmOn.png", this, menu_selector(RankingScene::bgm)); bgmItem->setPosition(ccp(w*4/5, h/8)); CCMenu* pMenu = CCMenu::create(playItem, bgmItem, reward, NULL); pMenu->setPosition(ccp(0,0)); this->addChild(pMenu); bgm_off = CCSprite::create("BgmOff.png"); bgm_off->setPosition(bgmItem->getPosition()); bgm_off->setVisible(GameManager::sharedGameManager()->getBgm()); if (GameManager::sharedGameManager()->getBgm()) { SimpleAudioEngine::sharedEngine()->setEffectsVolume(0.0f); } else { SimpleAudioEngine::sharedEngine()->setEffectsVolume(1.0f); } this->addChild(bgm_off); return true; }