bool ProceedController::init(){ if (!CCLayer::init()) { return false; } CCSize size = CCDirector::sharedDirector()->getWinSize(); //暂停按钮 CCMenuItemSprite *pause = this->instanceButton("pause1.png", "pause2.png", menu_selector(ProceedController::gamePauseFunc)); pause->setScale(1.5f); pause->setPosition(ccp(size.width - pause->getContentSize().width, size.height - pause->getContentSize().height)); //跳跃按钮 CCMenuItemSprite *jump = this->instanceButton("control_btn1.png", "control_btn2.png", menu_selector(ProceedController::gameJumpFunc)); jump->setScale(1.6f); jump->setPosition(ccp(size.width - jump->getContentSize().width - 50, 100)); //fever按钮 CCMenuItemSprite *fever = this->instanceButton("Fever_1_1.png", "Fever_1_1.png",menu_selector(ProceedController::gameFeverFunc)); fever->setScale(1.5f); fever->setOpacity(0.0f); fever->setPosition(ccp(jump->getPosition().x - fever->getContentSize().width * 2.0, jump->getPosition().y)); CCMenu *menu = CCMenu::create(pause,jump,fever,NULL); menu->setPosition(0, 0); this->addChild(menu,80); return true; }
bool CNFServerChangeLayer::InitLayer(int nCurrentServerID,int nServerTotalNum) { do { //初始化父类 CC_BREAK_IF(CCLayer::init()==false); m_nCurrentServerID = nCurrentServerID; /************************************************************************/ /* 背景图片 */ /************************************************************************/ //创建背景 CCSprite * pBg = CCSprite::create("ui/serverselect_bg.png"); CC_BREAK_IF(pBg==NULL); pBg->setPosition(SCREEN_CENTER); pBg->setScaleX( (float)CCDirector::sharedDirector()->getWinSize().width/(float)pBg->getContentSize().width ); addChild(pBg,enZOrderBack); //创建上次登录图片 CCSprite * pBg1 = CCSprite::create("ui/serverselect_title_1.png"); CC_BREAK_IF(pBg1==NULL); pBg1->setPosition(ccp(150+_NF_SCREEN_WIDTH_DIS_,420)); addChild(pBg1,enZOrderBack); //创建全服务器图片 CCSprite * pBg2 = CCSprite::create("ui/serverselect_title_2.png"); CC_BREAK_IF(pBg2==NULL); pBg2->setPosition(ccp(160+_NF_SCREEN_WIDTH_DIS_,300)); addChild(pBg2,enZOrderBack); /************************************************************************/ /* 创建按钮 */ /************************************************************************/ CCMenu * pMenu = CCMenu::create(); CC_BREAK_IF(pMenu==NULL); pMenu->setPosition(CCPointZero); addChild(pMenu,enZOrderFront); //创建返回按钮 //CCMenuItemSprite * pBtnBack = CCMenuItemSprite::create( // CCSprite::create("ui/serverselect_btn_back_n.png"), // CCSprite::create("ui/serverselect_btn_back_p.png"), // this, // menu_selector(CNFServerChangeLayer::OnBtnCallBack)); //CC_BREAK_IF(pBtnBack==NULL); //pBtnBack->setPosition(ccp(SCREEN_WIDTH - 30,SCREEN_HEIGHT-30)); //pMenu->addChild(pBtnBack,enZOrderFront); //创建当前服务器按钮 CCMenuItemSprite * pBtnCurrentServer = CCMenuItemSprite::create( CCSprite::create("ui/btn_enter_n.png"), CCSprite::create("ui/btn_enter_p.png"), this, menu_selector(CNFServerChangeLayer::OnBtnCallBack)); CC_BREAK_IF(pBtnCurrentServer==NULL); pBtnCurrentServer->setPosition(ccp(190+_NF_SCREEN_WIDTH_DIS_,380)); pMenu->addChild(pBtnCurrentServer,enZOrderFront); //创建左侧按钮 CCMenuItemSprite * pBtnLeft = CCMenuItemSprite::create( CCSprite::create("ui/serverselect_btn_back_n.png"), CCSprite::create("ui/serverselect_btn_back_p.png"), this, menu_selector(CNFServerChangeLayer::OnBtnLeftMove)); CC_BREAK_IF(pBtnLeft==NULL); pBtnLeft->setPosition(ccp(50+_NF_SCREEN_WIDTH_DIS_,150)); pMenu->addChild(pBtnLeft,enZOrderFront); //创建右侧按钮 CCMenuItemSprite * pBtnRight = CCMenuItemSprite::create( CCSprite::create("ui/serverselect_btn_back_n.png"), CCSprite::create("ui/serverselect_btn_back_p.png"), this, menu_selector(CNFServerChangeLayer::OnBtnRightMove)); CC_BREAK_IF(pBtnRight==NULL); pBtnRight->setPosition(ccp(SCREEN_WIDTH-_NF_SCREEN_WIDTH_DIS_-50,150)); pMenu->addChild(pBtnRight,enZOrderFront); /************************************************************************/ /* 创建label */ /************************************************************************/ CCDictionary *pDicLang = CCDictionary::createWithContentsOfFile("ui_xml/serverselect_xml.xml"); CC_BREAK_IF(pDicLang==NULL); //服务器名称label CCString *pStrServerName = dynamic_cast<CCString*>(pDicLang->objectForKey("server_name")); char szName[NAME_LEN] = {0}; sprintf(szName,pStrServerName->m_sString.c_str(),nCurrentServerID); CCLabelTTF * pLabelServerName = CCLabelTTF::create(szName,"Arial",20); CC_BREAK_IF(pLabelServerName==NULL); pLabelServerName->setPosition(pBtnCurrentServer->getPosition()); addChild(pLabelServerName,enZOrderFront); /************************************************************************/ /* 创建滑动层 */ /************************************************************************/ //创建滑动层 CNFServerChangeScrollLayer * pLayer = CNFServerChangeScrollLayer::CreateLayer(nServerTotalNum); //Item数组,x轴起始位置 CC_BREAK_IF(pLayer==NULL); pLayer->SetMsg(this); addChild(pLayer,enZOrderFront,enTagScrollLayer); return true; } while (false); CCLog("Fun CNFServerChangeLayer::init Error!"); return false; }
// on "init" you need to initialize your instance bool S11PrepareRes::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } //每个项目都要创建的东西 _menu = CCMenu::create(NULL); _menu->setPosition(CCPointZero); this->addChild(_menu, 101); titleString = ""; scriptMap=ScriptParser::paserScript("S11PrepareRes","leftTitle");//right_TableView_Map //背景图 { CCSprite * aSprite = CCSprite::create("s11Background.png"); aSprite->setPosition(ccp(visibleSize.width / 2, visibleSize.height / 2)); //CC_BREAK_IF(! aSprite); this->addChild(aSprite,98); aSprite ->getTexture()->setAntiAliasTexParameters();//抗锯齿 } //控件 { CCSprite * aSprite = CCSprite::create("s11NavBar.png"); aSprite->setAnchorPoint(ccp(0.0,1.0)); aSprite->setPosition(ccp(0,visibleSize.height-40)); this->addChild(aSprite,100); } { CCLabelTTF * leftTitleLabel = CCLabelTTF::create(s11Str2_macro,s11FontName_macro,s11TitleFontSize_macro); CCLabelTTF* pLabel = leftTitleLabel; pLabel->setColor(ccWHITE); pLabel->setPosition( s11Position3_macro(pLabel)); this->addChild(pLabel, 100); } titleLabel = CCLabelTTF::create(s11Str2_macro,s11FontName_macro,s11TitleFontSize_macro); CCLabelTTF* pLabel = titleLabel; pLabel->setColor(ccWHITE); pLabel->setPosition( s11Position4_macro(pLabel)); this->addChild(pLabel, 100); { CCSprite * aSprite = CCSprite::create("pRecButton.png"); aSprite->setPosition(s11Position1_macro(aSprite)); this->addChild(aSprite,100); CCSprite * aSprite1 = CCSprite::create("s11FullScreenIcon.png"); aSprite1->setPosition(s11Position1_macro(aItem)); this->addChild(aSprite1,100); CCSprite * sprite1 = CCSprite::create(); CCSprite * sprite2 = CCSprite::create(); CCMenuItemSprite *aItem = CCMenuItemSprite::create( sprite1, sprite2, this, menu_selector(S11PrepareRes::menuCloseCallback)); aItem->setPosition(s11Position1_macro(aItem)); aItem->setContentSize(aSprite->getContentSize()); _menu ->addChild(aItem,100); } CCTableView * tableView = CCTableView::create(this, s11Size1_macro); tableView->setAnchorPoint(ccp(0.0,0.0)); tableView->setDirection(kCCScrollViewDirectionVertical); tableView->setPosition(s11Position8_macro(tableView)); tableView->setDelegate(this); tableView->setVerticalFillOrder(kCCTableViewFillTopDown); this->addChild(tableView,99); tableView->reloadData(); std::string aStr = ScriptParser::readScript("s11TableCellTxt1.txt"); S11PrepareRes::detailString = aStr; rightDetailTex = CCLabelTTF::create(aStr.c_str(), "Helvetica", 30.0); rightDetailTex->setColor(ccBLACK); rightDetailTex-> setDimensions(s11Size2_macro); rightDetailTex->setPosition(s11Position9_macro(label)); this->addChild(rightDetailTex,100); //TabelBar { pTabBar = CCSprite::create("pTabBar.png"); pTabBar->setAnchorPoint(ccp(0.0,1.0)); pTabBar->setPosition(CCPointZero); this->addChild(pTabBar,100); } m_highlightSp = CCSprite::create("pTabBarSelectedHighlight.png"); { m_practiceSprite = CCSprite::create("pPencilIcon.png"); CCSprite * aSprite = m_practiceSprite; aSprite->setPosition(s11Position5_macro(aSprite)); this->addChild(aSprite,100); CCSprite * sprite1 = CCSprite::create(); CCSprite * sprite2 = CCSprite::create(); m_practiceItem = CCMenuItemSprite::create( sprite1, sprite2, this, menu_selector(S11PrepareRes::menuselect)); CCMenuItemSprite *aItem = m_practiceItem ; aItem->setTag(2); aItem->setPosition(s11Position5_macro(aItem)); aItem->setContentSize(m_highlightSp->getContentSize()); _menu ->addChild(aItem,100); m_touchedItem = m_practiceItem; m_practiceLabel = CCLabelTTF::create(s11Str1_macro,s11FontName_macro,s11FontSize_macro); CCLabelTTF* pLabel = m_practiceLabel; pLabel->setColor(s11White_macro); pLabel->setAnchorPoint(ccp(0.5,1.0)); pLabel->setPosition( ccp(aItem->getPosition().x,aItem->getPosition().y-aItem->getContentSize().height/2+11)); this->addChild(pLabel, 100); } { m_prepareSprite = CCSprite::create("pDocumentIconActive.png"); CCSprite * aSprite = m_prepareSprite; aSprite->setPosition(s11Position6_macro(aSprite)); this->addChild(aSprite,100); CCSprite * sprite1 = CCSprite::create(); CCSprite * sprite2 = CCSprite::create(); m_prepareItem = CCMenuItemSprite::create( sprite1, sprite2, this, menu_selector(S11PrepareRes::menuselect)); CCMenuItemSprite *aItem = m_prepareItem ; aItem->setTag(3); aItem->setPosition(s11Position6_macro(aItem)); aItem->setContentSize(m_highlightSp->getContentSize()); _menu ->addChild(aItem,100); m_prepareLabel = CCLabelTTF::create(s11Str2_macro,s11FontName_macro,s11FontSize_macro); CCLabelTTF* pLabel = m_prepareLabel; pLabel->setColor(s11Blue_macro); pLabel->setAnchorPoint(ccp(0.5,1.0)); pLabel->setPosition( ccp(aItem->getPosition().x,aItem->getPosition().y-aItem->getContentSize().height/2+11) ); this->addChild(pLabel, 100); } { m_settingSprite = CCSprite::create("pSettingsIcon.png"); CCSprite * aSprite = m_settingSprite; aSprite->setPosition(s11Position7_macro(aSprite)); this->addChild(aSprite,100); CCSprite * sprite1 = CCSprite::create(); CCSprite * sprite2 = CCSprite::create(); m_setting = CCMenuItemSprite::create( sprite1, sprite2, this, menu_selector(S11PrepareRes::menuselect)); CCMenuItemSprite *aItem = m_setting ; aItem->setTag(5); aItem->setPosition(s11Position7_macro(aItem)); aItem->setContentSize(m_highlightSp->getContentSize()); _menu ->addChild(aItem,100); m_settingLabel= CCLabelTTF::create(s11Str3_macro,s11FontName_macro,s11FontSize_macro); CCLabelTTF* pLabel = m_settingLabel; pLabel->setColor(s11Blue_macro); pLabel->setAnchorPoint(ccp(0.5,1.0)); pLabel->setPosition( ccp(aItem->getPosition().x,aItem->getPosition().y-aItem->getContentSize().height/2+11) ); this->addChild(pLabel, 100); } m_highlightSp->setPosition(ccp(m_prepareSprite->getPosition().x,pTabBar->getPosition().y+pTabBar->getContentSize().height/2)); this->addChild(m_highlightSp,100); m_highlightSp->setColor(ccc3(200, 200, 200)); return true; }
BaseSprite* MainLayerHerosBaseBody::getItemContentByIndex(unsigned int index) { BaseSprite* bg = BaseSprite::create("duiwu_yingxiong_bg.png"); bg->setPosition(ccp(bg->getContentSize().width/2,bg->getContentSize().height/2)); //图片 { ImageData data = ImageManager::getManager()->getImageData_ProfessionHead((Profession)mHerosVec[index]->getActorType()); CCLOG("----------------->%s",data.getCurrentImageFile().c_str()); BaseSprite *sprite = BaseSprite::create( data.getCurrentImageFile()); BaseSprite *sprite2 = BaseSprite::create( data.getCurrentImageFile()); BaseSprite *sprite3 = BaseSprite::create( data.getCurrentImageFile()); CCMenuItemSprite* heroItem = CCMenuItemSprite::create(sprite, sprite2, sprite3, this, menu_selector(MainLayerHerosBaseBody::menuItemClicked_heroImg)); CCMenu* menu = CCMenu::create(heroItem, NULL); bg->addChild(menu, 0, TAG_BaseBody_TABLE_HERO_IMG); heroItem->setPosition(ccp(74, bg->getContentSize().height/2)); menu->setPosition(CCPointZero); BaseSprite *biankuang = BaseSprite::create("renxing_renwu_touxiang_select.png"); bg->addChild(biankuang, 1); biankuang->setPosition(heroItem->getPosition()); BaseSprite *item = NULL; Profession iType = (Profession)mHerosVec[index]->getActorType(); if (iType == Profession_Yemanren) { item = BaseSprite::create("touxiang_jiaobiao_3.png"); } else if (iType == Profession_Chike) { item = BaseSprite::create("touxiang_jiaobiao_2.png"); } else if (iType == Profession_Fashi) { item = BaseSprite::create("touxiang_jiaobiao_1.png"); } else if (iType == Profession_Qishi) { item = BaseSprite::create("touxiang_jiaobiao_3.png"); } else if (iType == Profession_ShenJianShou) { item = BaseSprite::create("touxiang_jiaobiao_4.png"); } else if (iType == Profession_MiShu) { item = BaseSprite::create("touxiang_jiaobiao_1.png"); } else if (iType == Profession_WuSeng) { item = BaseSprite::create("touxiang_jiaobiao_5.png"); } else if (iType == Profession_YouXia) { item = BaseSprite::create("touxiang_jiaobiao_2.png"); } else if (iType == Profession_LieShou) { item = BaseSprite::create("touxiang_jiaobiao_4.png"); } else if (iType == Profession_WuShi) { item = BaseSprite::create("touxiang_jiaobiao_6.png"); } if (item) { item->setAnchorPoint(ccp(1, 0)); biankuang->addChild(item); item->setPosition(ccp(biankuang->getContentSize().width, 0)); } } //name HeroFixedPro info = BaseActorPropertyParser::getParser()->getExtraProerty((Profession)mHerosVec[index]->getActorType()); LF::lable(bg, info.nameInChinese,ccp(140, 106),22,fontStr_kaiti)->setTag(TAG_BaseBody_LABLE_NAME); // 英雄介绍 { Profession profId = mHerosVec[index]->getActorType(); CCLabelTTF *directionLabel = CCLabelTTF::create(getHeroDirectionByProfessionId(profId).c_str(), fontStr_kaiti, 20, CCSize(380, 0), kCCTextAlignmentLeft); bg->addChild(directionLabel, 1, Tag_Label_HeroDirection); directionLabel->setColor(ccc3(165, 125, 76)); directionLabel->setAnchorPoint(ccp(0, 1)); directionLabel->setPosition(ccp(140, 94)); } if (mFlag == 1) { CCMenuItemImage* chose = CCMenuItemImage::create( "duiwu_yingxiong_weixuanzhong.png" , "duiwu_yingxiong_weixuanzhong.png" , this, menu_selector(MainLayerHerosBaseBody::menuItemClicked_choseHero)); chose->setPosition(558, 83); CCMenu* menu = CCMenu::create(chose, NULL); menu->setPosition(CCPointZero); bg->addChild(menu, 0, TAG_Menu); CCSprite* unlock = CCSprite::create("duiwu_yingxiong_unlock.png", CCRect(0, 0, 610, 129)); bg->addChild(unlock, 0, TAG_Unlock); unlock->setOpacity(200); unlock->setPosition(bg->getPosition()); int state = mChoseHeroState.at(index); if(state>=1 && state<=4) //已选中的 { chose->initWithNormalImage( "duiwu_yingxiong_xuanzhong.png" , "duiwu_yingxiong_xuanzhong.png" , "duiwu_yingxiong_xuanzhong.png" , this, menu_selector(MainLayerHerosBaseBody::menuItemClicked_choseHero)); unlock->setVisible(false); } else if(state == 0 && mChoseNum<3) //未选中 可选的 { chose->initWithNormalImage( "duiwu_yingxiong_daixuan.png" , "duiwu_yingxiong_daixuan.png" , "duiwu_yingxiong_daixuan.png" , this, menu_selector(MainLayerHerosBaseBody::menuItemClicked_choseHero)); unlock->setVisible(false); } else //选满了、不能选的 { bg->initWithFile("duiwu_yingxiong_bg_suoding.png"); } } else if (mFlag == 2) { if (mHerosVec.at(index)->canUnlock()) { //可解锁 CCMenuItemImage* kjsItem = CCMenuItemImage::create( "duiwu_yingxiong_jiesuo.png" , "duiwu_yingxiong_jiesuo.png" , this, menu_selector(MainLayerHerosBaseBody::menuItemClicked_jiesuoHero)); kjsItem->setPosition(558, 83); kjsItem->setTag(index); CCMenu* menu = CCMenu::create(kjsItem, NULL); menu->setPosition(CCPointZero); bg->addChild(menu, 0, TAG_Menu); } else //还不能解锁 { //不能解锁 CCMenuItemImage* kjsItem = CCMenuItemImage::create( "duiwu_yingxiong_suoding.png" , "duiwu_yingxiong_suoding.png" , this, menu_selector(MainLayerHerosBaseBody::menuItemClicked_jiesuoHero)); kjsItem->setPosition(558, 83); kjsItem->setTag(index); CCMenu* menu = CCMenu::create(kjsItem, NULL); menu->setPosition(CCPointZero); bg->addChild(menu, 0, TAG_Menu); CCSprite* unlock = CCSprite::create("duiwu_yingxiong_unlock.png", CCRect(0, 0, 610, 129)); bg->addChild(unlock, 0, TAG_Unlock); unlock->setOpacity(200); unlock->setPosition(bg->getPosition()); } } return bg; }
bool MultiplayerLayer::init() { bool bRet = false; do { CC_BREAK_IF(! OverlayBase::init()); CCSize size = CCDirector::sharedDirector()->getWinSize(); int leftSpace = 100; _opponentType = kHuman; CCMenuItemSprite* hItem = createMenuItemSprite((char*)"btnHotSeat128x128.png", (char*)"btnHotSeatPressed.png", menu_selector(MultiplayerLayer::onHotSeat)); CCMenuItemSprite* onlineItem = createMenuItemSprite((char*)"btnOnlineGame128x128.png", (char*)"btnOnlineGamePressed.png", menu_selector(MultiplayerLayer::onOnlineGame)); CCMenu* menu = CCMenu::create(hItem, onlineItem, NULL); menu->alignItemsVertically(); menu->setPosition(ccp(leftSpace, size.height - 2 * leftSpace)); addChild(menu, 1); if (!sgl_ConnectionManager.getRoomNumber().empty()) { CCMenuItemSprite* onlineReconnectItem = createMenuItemSprite((char*)"btnOnlineGameReconnect.png", (char*)"btnOnlineGamePressed.png", menu_selector(MultiplayerLayer::onOnlineGame)); menu->cocos2d::CCNode::addChild(onlineReconnectItem); } float menuLimit = hItem->getPosition().x + hItem->boundingBox().size.width + 20; CCLabelTTF* lH = new CCLabelTTF(); lH->initWithString("Hot seat", S_F_TYPE.c_str(), 32); lH->setPosition(ccp(menuLimit, hItem->getPosition().y)); lH->setAnchorPoint(ccp(0,0)); hItem->addChild(lH); CCLabelTTF* lO = new CCLabelTTF(); lO->initWithString("Random online game", S_F_TYPE.c_str(), 32); lO->setPosition(ccp(menuLimit, hItem->getPosition().y)); lO->setAnchorPoint(ccp(0,0)); onlineItem->addChild(lO); //Cancel - Go Menu CCMenuItemSprite* mRightArrow = sgl_SpriteFactory.createMenuItemSprite("btnArrow_Back128x128.png", "btnArrow_Back128x128Pressed.png", menu_selector(MultiplayerLayer::onQuit), this); CCMenu* menuReturn = CCMenu::create(mRightArrow, NULL); CCMenuItemSprite* mLeftArrow = sgl_SpriteFactory.createMenuItemSprite("btnArrow128x128.png", "btnArrow128x128Pressed.png", menu_selector(MultiplayerLayer::onConnect), this); CCMenu* mStartGame = CCMenu::create(mLeftArrow, NULL); menuReturn->setPosition(leftSpace, 150); mStartGame->setPosition(size.width - leftSpace - mLeftArrow->boundingBox().size.width * 0.5f, 150); addChild(mStartGame); addChild(menuReturn); _connectionStatus = CCLabelTTF::create("", S_F_TYPE.c_str(), 32); _connectionStatus->setPosition(ccp(size.width/2, 150)); this->addChild(_connectionStatus); bRet = true; } while (0); return bRet; }
bool CNFRockerLayer::InitLayer(CNF3DWorldLayer * pLayer,int nStageID) { do { //初始化父类 CC_BREAK_IF(CCLayerColor::initWithColor(ccc4(255,0,0,50))==false); //注册 CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,-1,false); //设置层大小 setContentSize(CCSizeMake(200,200));//(CCSizeMake(SCREEN_WIDTH*0.5f,SCREEN_HEIGHT)); m_p3DLayer = pLayer; m_bIsTouching = false; m_bIsPublicCD = false; m_fRockerSpeed = _NF_ROCKER_SPEED_; //摇杆的移动速度 m_fRockerMaxDis = _NF_ROCKER_MAX_DIS_; //摇杆最大偏移量 m_nStageID = nStageID; //主角技能ID CNFProtagonist * pPro = dynamic_cast<CNFProtagonist *>(pLayer->getChildByTag(enTagProtagonist)); CC_BREAK_IF(pPro==NULL); m_nSkill_1_ID = pPro->GetSkillInfo_1().nSkill_SkillItemID; m_nSkill_2_ID = pPro->GetSkillInfo_2().nSkill_SkillItemID; m_nSkill_3_ID = pPro->GetSkillInfo_3().nSkill_SkillItemID; m_nSkill_4_ID = pPro->GetSkillInfo_4().nSkill_SkillItemID; m_nSkill_5_ID = pPro->GetSkillInfo_5().nSkill_SkillItemID; //创建摇杆背景 CCSprite * pRockerBg = CCSprite::create("gameui/rocker_bg.png"); CC_BREAK_IF(pRockerBg==NULL); //pRockerBg->setScale(2.5f); pRockerBg->setPosition(ccp(100,100)); addChild(pRockerBg,enZOrderFront,enTagRockerBg); pRockerBg->setOpacity(100.f); //创建摇杆 CCSprite * pRocker = CCSprite::create("gameui/rocker_ball.png"); CC_BREAK_IF(pRocker==NULL); pRocker->setPosition(pRockerBg->getPosition()); addChild(pRocker,enZOrderFront+1,enTagRocker); pRocker->setOpacity(100.f); //若为副本,则创建按钮 if (m_nStageID >= _NF_TOWN_OR_BATTLE_ID_ && m_nStageID <_NF_TOWN_FB_ID_) { /************************************************************************/ /* 创建按钮 */ /************************************************************************/ //创建菜单 CCMenu * pMenu = CCMenu::create(); CC_BREAK_IF(pMenu==NULL); pMenu->setPosition(CCPointZero); addChild(pMenu,enZOrderFront,enTagMenu); //创建普通攻击按钮 CCSprite * pCommon1 = CCSprite::create("gameui/skill_common.png"); CC_BREAK_IF(pCommon1==NULL); CCSprite * pCommon2 = CCSprite::create("gameui/skill_common.png"); CC_BREAK_IF(pCommon2==NULL); pCommon2->setOpacity(150.f); CCMenuItemSprite * pBtnCommon = CCMenuItemSprite::create(pCommon1,pCommon2,this,menu_selector(CNFRockerLayer::OnBtnCallBack)); CC_BREAK_IF(pBtnCommon==NULL); pBtnCommon->setPosition(ccp(SCREEN_WIDTH - 60,58)); pMenu->addChild(pBtnCommon,enZOrderFront,enTagBtnCommonAttack); CCLabelBMFont* pCommonAttackFont = CCLabelBMFont::create("1","fonts/mhp_num.fnt"); pCommonAttackFont->setPosition(pBtnCommon->getPosition()); this->addChild(pCommonAttackFont,enZOrderFront,enTagCommonAttackFont); CCSprite * pCommon3 = CCSprite::create("gameui/skill_common.png"); CC_BREAK_IF(pCommon3==NULL); pCommon3->setColor(ccRED); pCommon3->setOpacity(100.f); //创建普通攻击CD CCProgressTimer* pProgressCommonAttackCD = CCProgressTimer::create(pCommon3); CC_BREAK_IF(pProgressCommonAttackCD==NULL); pProgressCommonAttackCD->setType(kCCProgressTimerTypeRadial); pProgressCommonAttackCD->setMidpoint(ccp(0.5f,0.5f)); pProgressCommonAttackCD->setPercentage(0.f); pProgressCommonAttackCD->setPosition(pBtnCommon->getPosition()); this->addChild(pProgressCommonAttackCD,enZOrderFront+1,enTagCommonAttackCD); //创建技能按钮 for (int i=enTagBtnSkill1;i<=enTagBtnSkill5;i++) { char szName[NAME_LEN] = {0}; int skilltemp = -1; if(i==enTagBtnSkill1){ skilltemp = m_nSkill_1_ID; }else if(i==enTagBtnSkill2){ skilltemp = m_nSkill_2_ID; }else if(i==enTagBtnSkill3){ skilltemp = m_nSkill_3_ID; }else if(i==enTagBtnSkill4){ skilltemp = m_nSkill_4_ID; }else if(i==enTagBtnSkill5){ skilltemp = m_nSkill_5_ID; } if(skilltemp==-1){ continue; } sprintf(szName,"Skill/r%d_s%d.png",pPro->GetRoleID(),skilltemp); CCSprite * pSpr_n = CCSprite::create(szName); CC_BREAK_IF(pSpr_n==NULL); CCSprite * pSpr_p = CCSprite::create(szName); CC_BREAK_IF(pSpr_p==NULL);; pSpr_p->setColor(ccBLUE); CCSprite * pSpr_d = CCSprite::create(szName); CC_BREAK_IF(pSpr_d==NULL); pSpr_d->setOpacity(150.f); CCSprite * pSpr_CD = CCSprite::create(szName); CC_BREAK_IF(pSpr_CD==NULL); pSpr_CD->setColor(ccRED); //创建技能按钮 CCMenuItemSprite * pBtn = CCMenuItemSprite::create(pSpr_n,pSpr_p,pSpr_d,this,menu_selector(CNFRockerLayer::OnBtnCallBack)); CC_BREAK_IF(pBtn==NULL); pMenu->addChild(pBtn,enZOrderFront,i); if(i==enTagBtnSkill1) pBtn->setPosition(ccp(pBtnCommon->getPositionX()+10,pBtnCommon->getPositionY()+90)); else if(i==enTagBtnSkill2) pBtn->setPosition(ccp(pBtnCommon->getPositionX()-110,pBtnCommon->getPositionY()-5)); else if(i==enTagBtnSkill3) pBtn->setPosition(ccp(pBtnCommon->getPositionX()-70,pBtnCommon->getPositionY()+70)); else if(i==enTagBtnSkill4) pBtn->setPosition(ccp(pBtnCommon->getPositionX()-200,pBtnCommon->getPositionY()-5)); else if(i==enTagBtnSkill5) pBtn->setPosition(ccp(pBtnCommon->getPositionX()+10,pBtnCommon->getPositionY()+170)); //创建技能CD CCProgressTimer* pProgress = CCProgressTimer::create(pSpr_p); CC_BREAK_IF(pProgress==NULL); pProgress->setType(kCCProgressTimerTypeRadial); pProgress->setMidpoint(ccp(0.5f,0.5f)); pProgress->setPercentage(0.f); pProgress->setPosition(pBtn->getPosition()); this->addChild(pProgress,enZOrderFront+1,i+100); //技能CD标签 = 技能标签 + 100 //创建公共CD CCProgressTimer* pProgressCD = CCProgressTimer::create(pSpr_CD); CC_BREAK_IF(pProgressCD==NULL); pProgressCD->setType(kCCProgressTimerTypeRadial); pProgressCD->setMidpoint(ccp(0.5f,0.5f)); pProgressCD->setPercentage(0.f); pProgressCD->setPosition(pBtn->getPosition()); this->addChild(pProgressCD,enZOrderFront+2,i+200); //技能CD标签 = 技能标签 + 200 pProgressCD->setVisible(false); } } //更新函数 schedule(schedule_selector(CNFRockerLayer::update)); return true; } while (false); CCLog("Fun CNFRockerLayer::InitLayer Error!"); return false; }