大佬教程收集整理的这篇文章主要介绍了分析Cocos2d-x横版ACT手游源代码 6、创建忍队界面,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
.h头文件代码
#ifndef _NF_TEAM_CREATE_SCENE_HEAD_ #define _NF_TEAM_CREATE_SCENE_HEAD_ #include "../publicdef/PublicDef.h" /************************************************************************/ /*创建忍队层 */ /************************************************************************/ class CNFTeamCreateLayer : public CCLayer { protected: //标签 enum { enTagstudioMainUiLayer,enTagRole,}; int m_nRolEID; //角色ID 1.鸣人 2.小樱 3.佐助 public: static CNFTeamCreateLayer * CreateLayer(); static CCScene * scene(); void OnGameStartPage(CCObject *pSender,TouchEventType typE); //创建人物 void textFieldEvent(CCObject* pSender,TextFiledEventType typE); void OnBACkToLoginPage(CCObject *pSender,TouchEventType typE); //返回登录界面 void OnRoleSELEct(CCObject *pSender,TouchEventType typE); //角色选择界面 protected: virtual bool init(); }; #endif
。cpp代码
#include "NFRoleSELEctLayer.h" #include "NFTownScene.h" #include "NFLoginScene.h" #include "NFCreateTeamLayer.h" #include "datamanager/NFServerDataManager.h" /************************************************************************/ /*创建忍队层<span style="white-space:pre"> </span>*/ /************************************************************************/ CCScene * CNFTeamCreateLayer::scene() { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>CCScene* pScene = CCScene::create(); <span style="white-space:pre"> </span>CC_BREAK_IF(pScene==null); <span style="white-space:pre"> </span>CNFTeamCreateLayer* pLayer = CNFTeamCreateLayer::CreateLayer(); <span style="white-space:pre"> </span>CC_BREAK_IF(pLayer==null); <span style="white-space:pre"> </span>pScene->addChild(pLayer); <span style="white-space:pre"> </span>return pScene; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("Fun CNFTeamCreateLayer::scene Error!"); <span style="white-space:pre"> </span>return NULL; } CNFTeamCreateLayer * CNFTeamCreateLayer::CreateLayer() { <span style="white-space:pre"> </span>CNFTeamCreateLayer *pRet = new CNFTeamCreateLayer(); <span style="white-space:pre"> </span>if (pRet && pRet->init()) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>pRet->autorelease(); <span style="white-space:pre"> </span>return pRet; <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>CCLog("Fun CNFTeamCreateLayer::CreateLayer Error!"); <span style="white-space:pre"> </span>delete pRet; <span style="white-space:pre"> </span>pRet = NULL; <span style="white-space:pre"> </span>return NULL; } bool CNFTeamCreateLayer::init() { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//初始化父类 <span style="white-space:pre"> </span>CC_BREAK_IF(CCLayer::init()==falsE); <span style="white-space:pre"> </span>m_nRolEID = 1; <span style="white-space:pre"> </span>//创建主场景UI层 <span style="white-space:pre"> </span>UILayer* pUiLayer = UILayer::create(); <span style="white-space:pre"> </span>CC_BREAK_IF(pUiLayer==null); <span style="white-space:pre"> </span>//-------------------加入主场景UI---------------------------- <span style="white-space:pre"> </span>UILayout *pCreateNinja = dynamic_cast<UILayout*><span style="white-space:pre"> </span>(GUIReader::shareReader()->widgetFromJsonFile("CreateNinja.json")); <span style="white-space:pre"> </span>CC_BREAK_IF(pCreateNinja==null); <span style="white-space:pre"> </span>pUiLayer->addWidget(pCreateNinja); <span style="white-space:pre"> </span>pCreateNinja->setName("CreateNinjaLayer"); <span style="white-space:pre"> </span>pCreateNinja->setSize(getContentSize()); <span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/xiaoyin.ExportJson"); <span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/NewProject.ExportJson"); <span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/minren1.ExportJson"); <span style="white-space:pre"> </span>//获取返回按钮 <span style="white-space:pre"> </span>UIButton *pBtn_BACk=dynamic_cast<UIButton*>(pCreateNinja->getChildByName("MainUi")->getChildByName("Btn_Return")); <span style="white-space:pre"> </span>CC_BREAK_IF(pBtn_BACk==null); <span style="white-space:pre"> </span>pBtn_BACk->addTouchEventListener(this,toucheventSELEctor(CNFTeamCreateLayer::OnBACkToLoginPagE)); <span style="white-space:pre"> </span>//获取开始按钮 <span style="white-space:pre"> </span>UIButton *pBtn_create_team=dynamic_cast<UIButton*>(pCreateNinja->getChildByName("MainUi")->getChildByName("Btn_create_team")); <span style="white-space:pre"> </span>CC_BREAK_IF(pBtn_create_team==null); <span style="white-space:pre"> </span>pBtn_create_team->addTouchEventListener(this,toucheventSELEctor(CNFTeamCreateLayer::OnGameStartPagE)); <span style="white-space:pre"> </span>//获取输入框 UITextField* pTextField = dynamic_cast<UITextField*>(pCreateNinja->getChildByName("MainUi")->getChildByName("Team_Name_TextField")); <span style="white-space:pre"> </span>CC_BREAK_IF(pTextField==null); <span style="white-space:pre"> </span>pTextField->setTouchEnabled(true); pTextField->addEventListenerTextField(this,textfieldeventSELEctor(CNFTeamCreateLayer::textFieldEvent)); <span style="white-space:pre"> </span>pTextField->setText(""); <span style="white-space:pre"> </span>for (int i=0;i<3;i++) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//获取人物按钮 <span style="white-space:pre"> </span>UIButton *pBtn_Role=dynamic_cast<UIButton*>(pCreateNinja->getChildByName("MainUi")->getChildByName(CCString::createWithFormat("Btn_Char_%d",i+1)->getCString())); <span style="white-space:pre"> </span>CC_BREAK_IF(pBtn_Role==null); <span style="white-space:pre"> </span>pBtn_Role->addTouchEventListener(this,toucheventSELEctor(CNFTeamCreateLayer::OnRoleSELEct)); <span style="white-space:pre"> </span>if (i==0) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//获取按下图片 <span style="white-space:pre"> </span>UIImageView *pSELEct_Img=dynamic_cast<UIImageView*>(pBtn_Role->getChildByName("SELEct_Img")); <span style="white-space:pre"> </span>CC_BREAK_IF(pSELEct_Img==null); <span style="white-space:pre"> </span>pSELEct_Img->setVisible(true); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/xiaoyin.ExportJson"); <span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/NewProject.ExportJson"); <span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armature/minren1.ExportJson"); <span style="white-space:pre"> </span>char cName[3][256]={"minren1","xiaoyin","NewProject"}; <span style="white-space:pre"> </span>CCArmature *pRole = CCArmature::create(cName[0]); <span style="white-space:pre"> </span>CC_BREAK_IF(pRole==null); <span style="white-space:pre"> </span>pRole->setPosition(ccp(SCREEN_WIDTH/2,210)); <span style="white-space:pre"> </span>pRole->setAnchorPoint(ccp(pRole->getAnchorPoint().x,0)); <span style="white-space:pre"> </span>pRole->getAnimation()->play("hold",-1,10000); <span style="white-space:pre"> </span>addChild(pRole,enZOrderMid,enTagRolE); <span style="white-space:pre"> </span> <span style="white-space:pre"> </span>addChild(pUiLayer,enZOrderBACk,enTagstudioMainUiLayer); <span style="white-space:pre"> </span>return true; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("Fun CNFTeamCreateLayer::init Error!"); <span style="white-space:pre"> </span>return false; } void CNFTeamCreateLayer::OnGameStartPage( CCObject *pSender,TouchEventType type ) { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>switch (typE) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>case TOUCH_EVENT_ENDED: <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>if(m_nRolEID==0)return; <span style="white-space:pre"> </span>UILayer* pMainUiLayer = dynamic_cast<UILayer*>(getChildByTag(enTagstudioMainUiLayer)); <span style="white-space:pre"> </span>CC_BREAK_IF(pMainUiLayer==null); <span style="white-space:pre"> </span>UILayout *pCreateNinja = dynamic_cast<UILayout*>(pMainUiLayer->getWidgetByName("CreateNinjaLayer")); <span style="white-space:pre"> </span>CC_BREAK_IF(pCreateNinja==null); <span style="white-space:pre"> </span>//获取输入框 <span style="white-space:pre"> </span>UITextField* pTextField = dynamic_cast<UITextField*>(pCreateNinja->getChildByName("MainUi")->getChildByName("Team_Name_TextField")); <span style="white-space:pre"> </span>CC_BREAK_IF(pTextField==null); <span style="white-space:pre"> </span>if(strcmp(pTextField->getstringvalue(),"")==0)return; <span style="white-space:pre"> </span> <span style="white-space:pre"> </span>//读取角色信息 <span style="white-space:pre"> </span>CNFServerRoleSELEcTinfoVec RoleSELEcTinfoVec; <span style="white-space:pre"> </span>CNFServerDataManager::SharedData()->GetRoleSELEcTinfo(RoleSELEcTinfoVec); <span style="white-space:pre"> </span>CNFServerRoleSELEcTinfoVec::iterator itRole=RoleSELEcTinfoVec.begin(); <span style="white-space:pre"> </span>for (;itRole!=RoleSELEcTinfoVec.end();itRole++) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>if (itRole->nRolEID==m_nRolEID) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>itRole->nState=0; <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>CNFServerDataManager::SharedData()->SetRoleSELEcTinfo(RoleSELEcTinfoVec); <span style="white-space:pre"> </span>//人物选择场景 <span style="white-space:pre"> </span>CCScene * pScene = CNFRoleSELEctLayer::scene(); <span style="white-space:pre"> </span>CC_BREAK_IF(pScene==null); <span style="white-space:pre"> </span>CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1.f,pScenE)); <span style="white-space:pre"> </span>}break; <span style="white-space:pre"> </span>default: <span style="white-space:pre"> </span>break; <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>return; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("CNFTeamCreateLayer::OnGameStartPage Error"); } void CNFTeamCreateLayer::textFieldEvent( CCObject* pSender,TextFiledEventType type ) { } void CNFTeamCreateLayer::OnBACkToLoginPage( CCObject *pSender,TouchEventType type ) { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//跳转到登陆界面 <span style="white-space:pre"> </span>CCScene * pScene = CNFLoginScene::scene(); <span style="white-space:pre"> </span>CC_BREAK_IF(pScene==null); <span style="white-space:pre"> </span>CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(1.f,pScenE)); <span style="white-space:pre"> </span>return; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("CNFTeamCreateLayer::OnBACkToLoginPage Error"); } void CNFTeamCreateLayer::OnRoleSELEct( CCObject *pSender,TouchEventType type ) { <span style="white-space:pre"> </span>do <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>UILayer* pMainUiLayer = dynamic_cast<UILayer*>(getChildByTag(enTagstudioMainUiLayer)); <span style="white-space:pre"> </span>CC_BREAK_IF(pMainUiLayer==null); <span style="white-space:pre"> </span>UILayout *pCreateNinja = dynamic_cast<UILayout*><span style="white-space:pre"> </span>(pMainUiLayer->getWidgetByName("CreateNinjaLayer")); <span style="white-space:pre"> </span>CC_BREAK_IF(pCreateNinja==null); <span style="white-space:pre"> </span>for (int i=0;i<3;i++) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>//获取人物按钮 <span style="white-space:pre"> </span>UIButton *pBtn_Role=dynamic_cast<UIButton*>(pCreateNinja->getChildByName("MainUi")->getChildByName(CCString::createWithFormat("Btn_Char_%d",i+1)->getCString())); <span style="white-space:pre"> </span>CC_BREAK_IF(pBtn_Role==null); <span style="white-space:pre"> </span>//获取按下图片 <span style="white-space:pre"> </span>UIImageView *pSELEct_Img=dynamic_cast<UIImageView*>(pBtn_Role->getChildByName("SELEct_Img")); <span style="white-space:pre"> </span>CC_BREAK_IF(pSELEct_Img==null); <span style="white-space:pre"> </span>if (pBtn_Role==pSender) <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>pSELEct_Img->setVisible(true); <span style="white-space:pre"> </span>m_nRolEID=i+1; <span style="white-space:pre"> </span>removeChildByTag(enTagRolE); <span style="white-space:pre"> </span>char cName[3][256]={"minren1","NewProject"}; <span style="white-space:pre"> </span>CCArmature *pRole = CCArmature::create(cName[i]); <span style="white-space:pre"> </span>CC_BREAK_IF(pRole==null); <span style="white-space:pre"> </span>pRole->setPosition(ccp(SCREEN_WIDTH/2,210)); <span style="white-space:pre"> </span>pRole->setAnchorPoint(ccp(pRole->getAnchorPoint().x,0)); <span style="white-space:pre"> </span>pRole->getAnimation()->play("hold",10000); <span style="white-space:pre"> </span>addChild(pRole,enTagRolE); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>else <span style="white-space:pre"> </span>{ <span style="white-space:pre"> </span>pSELEct_Img->setVisible(false); <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>return; <span style="white-space:pre"> </span>} while (false); <span style="white-space:pre"> </span>CCLog("CNFTeamCreateLayer::OnRoleSELEct Error"); } 个人博客 www.sundaboke.com
以上是大佬教程为你收集整理的分析Cocos2d-x横版ACT手游源代码 6、创建忍队界面全部内容,希望文章能够帮你解决分析Cocos2d-x横版ACT手游源代码 6、创建忍队界面所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。