分析Cocos2d-x横版ACT手游源 1、登录
我自己的游戏代码 因为 游戏源 盯着外面的 我们能够能够理解
/************************************************************************/
/* 登录场景 */
/************************************************************************/
class CNFLoginScene : public CCLayer ,public CMsgReceiver
{
protected:
//标签
enum
{
enTagLoading = 1,
enTagServerNameLabel,
enTagStudioLoginLayer, //登陆层
enTagStudioRegisterLayer, //注冊层
}; int m_nLoadRecNum; //资源载入数
int m_nLoadRecTotalNum; //资源载入总数 int m_nCurrentServerID; //当前serverID
int m_nServerTotalNum; //server的总数量 public:
static CCScene * scene(); static CNFLoginScene * CreateLayer(); //消息接收
virtual void RecMsg(int nMsgID,void* pInfo,int nSize); protected:
virtual void onEnter(); //资源预载入
void LoadRec(); void OnLoadRecCallBack(CCObject *pObj); //回调:资源载入
// void OnLoadLastRecCallBack(CCObject *pObj); //回调:最后一个资源载入 //异步载入骨骼资源的回调
void OnLoadArmatureData(float percent); virtual void InitSceneUI(); //在这里载入该图层专用的资源 //---------------登录页button回调----------------
void OnBtnEnterCallBack(CCObject *pSender, TouchEventType type); //開始游戏
void OnBtnServerSelectCallBack(CCObject *pSender, TouchEventType type); //选择server
void OnBtnSwitchToRegisterCallBack(CCObject *pSender, TouchEventType type); //跳转到注冊页
void OnBtnLoginCallBack(CCObject *pSender, TouchEventType type); //登录
void OnAccountTextFieldEvent(CCObject *pSender, TextFiledEventType type); //---------------注冊页button回调----------------
void OnBackToLoginCallBack(CCObject *pSender, TouchEventType type); //跳转到登录页
void OnBtnRegisterCallBack(CCObject *pSender, TouchEventType type); //注冊
}; #endif
.cpp文件
#define _LOADREC_NUM_<span style="white-space:pre"> </span>16
/************************************************************************/
/*<span style="white-space:pre"> </span>登录场景<span style="white-space:pre"> </span>*/
/************************************************************************/
CCScene* CNFLoginScene::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>CNFLoginScene* pLayer = CNFLoginScene::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 CNFLoginScene::scene Error!");
<span style="white-space:pre"> </span>return NULL;
} CNFLoginScene * CNFLoginScene::CreateLayer()
{
<span style="white-space:pre"> </span>CNFLoginScene *pRet = new CNFLoginScene();
<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 CNFLoginScene::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;
} void CNFLoginScene::onEnter()
{
<span style="white-space:pre"> </span>CCLayer::onEnter();
<span style="white-space:pre"> </span>do
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>//创建Laoding层
<span style="white-space:pre"> </span>CNFLoadingLayer * pLoading = CNFLoadingLayer::CreateLayer();
<span style="white-space:pre"> </span>CC_BREAK_IF(pLoading==NULL);
<span style="white-space:pre"> </span>addChild(pLoading,enZOrderFront+10000,enTagLoading);
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>m_nLoadRecNum = 0;
<span style="white-space:pre"> </span>m_nLoadRecTotalNum = _LOADREC_NUM_; <span style="white-space:pre"> </span>//预载入本层资源
<span style="white-space:pre"> </span>LoadRec(); <span style="white-space:pre"> </span>return ;
<span style="white-space:pre"> </span>} while (false);
<span style="white-space:pre"> </span>CCLog("Fun CNFLoginScene::onEnter Error!");
} //资源预载入
void CNFLoginScene::LoadRec()
{
<span style="white-space:pre"> </span>CCTextureCache::sharedTextureCache()->addImageAsync("ui/serverselect_bg.png",this,callfuncO_selector(CNFLoginScene::OnLoadRecCallBack));
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/kulougongshou.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/kulouzhanshi.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/mayi.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/bianyikunchong.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/bubing.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/xiaoyin.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/NewProject.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/minren1.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData)); <span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/kulou_arrow.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData)); <span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/naili.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/NPC_kakaxi.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/portal.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData)); <span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/hited_light.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/public_casting.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre"> </span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/skill_light_1.ExportJson",this,schedule_selector(CNFLoginScene::OnLoadArmatureData));
} void CNFLoginScene::OnLoadArmatureData( float percent )
{
<span style="white-space:pre"> </span>//CCLog("==================%f",percent);
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>m_nLoadRecNum ++; <span style="white-space:pre"> </span>//得到Laoding层
<span style="white-space:pre"> </span>CNFLoadingLayer * pLoading = dynamic_cast<CNFLoadingLayer *>(getChildByTag(enTagLoading));
<span style="white-space:pre"> </span>if(pLoading!=NULL){
<span style="white-space:pre"> </span>pLoading->SetPro( (float)m_nLoadRecNum/(float)m_nLoadRecTotalNum );
<span style="white-space:pre"> </span>}else{
<span style="white-space:pre"> </span>CCLog("Fun CNFLoginScene::OnLoadArmatureData Error!");
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>if(m_nLoadRecNum==m_nLoadRecTotalNum){
<span style="white-space:pre"> </span>//延迟1秒
<span style="white-space:pre"> </span>this->runAction(CCSequence::create(
<span style="white-space:pre"> </span>CCDelayTime::create(2.f),
<span style="white-space:pre"> </span>CCCallFunc::create(this,callfunc_selector(CNFLoginScene::InitSceneUI)),
<span style="white-space:pre"> </span>NULL));
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>if (percent >= 1)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>CCLog("addArmatureFileInfoAsync over");
<span style="white-space:pre"> </span>}
} //资源载入回调
void CNFLoginScene::OnLoadRecCallBack( CCObject *pObj )
{
<span style="white-space:pre"> </span>do
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>m_nLoadRecNum ++; <span style="white-space:pre"> </span>//得到Laoding层
<span style="white-space:pre"> </span>CNFLoadingLayer * pLoading = dynamic_cast<CNFLoadingLayer *>(getChildByTag(enTagLoading));
<span style="white-space:pre"> </span>CC_BREAK_IF(pLoading==NULL);
<span style="white-space:pre"> </span>pLoading->SetPro( (float)m_nLoadRecNum/(float)m_nLoadRecTotalNum ); <span style="white-space:pre"> </span>if(m_nLoadRecNum==m_nLoadRecTotalNum){
<span style="white-space:pre"> </span>//延迟1秒
<span style="white-space:pre"> </span>this->runAction(CCSequence::create(
<span style="white-space:pre"> </span>CCDelayTime::create(2.f),
<span style="white-space:pre"> </span>CCCallFunc::create(this,callfunc_selector(CNFLoginScene::InitSceneUI)),
<span style="white-space:pre"> </span>NULL));
<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("Fun CNFLoginScene::OnLoadRecCallBack Error!");
} // //最后一个资源载入回调
// void CNFLoginScene::OnLoadLastRecCallBack( CCObject *pObj )
// {
// <span style="white-space:pre"> </span>do
// <span style="white-space:pre"> </span>{
// <span style="white-space:pre"> </span>//CCLog("==================last");
// <span style="white-space:pre"> </span>m_nLoadRecNum ++;
//
// <span style="white-space:pre"> </span>//得到Laoding层
// <span style="white-space:pre"> </span>CNFLoadingLayer * pLoading = dynamic_cast<CNFLoadingLayer *>(getChildByTag(enTagLoading));
// <span style="white-space:pre"> </span>CC_BREAK_IF(pLoading==NULL);
// <span style="white-space:pre"> </span>pLoading->SetPro( 1.f );
//
// <span style="white-space:pre"> </span>//延迟1秒
// <span style="white-space:pre"> </span>this->runAction(CCSequence::create(
// <span style="white-space:pre"> </span>CCDelayTime::create(1.f),
// <span style="white-space:pre"> </span>CCCallFunc::create(this,callfunc_selector(CNFLoginScene::InitSceneUI)),
// <span style="white-space:pre"> </span>NULL));
//
// <span style="white-space:pre"> </span>return ;
// <span style="white-space:pre"> </span>} while (false);
// <span style="white-space:pre"> </span>CCLog("Fun CNFLoginScene::OnLoadLastRecCallBack Error!");
// } void CNFLoginScene::InitSceneUI()
{
<span style="white-space:pre"> </span>do
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>//移除Laoding层
<span style="white-space:pre"> </span>CNFLoadingLayer * pLoading = dynamic_cast<CNFLoadingLayer *>(getChildByTag(enTagLoading));
<span style="white-space:pre"> </span>if (pLoading!=NULL)
<span style="white-space:pre"> </span>removeChildByTag(enTagLoading,true); <span style="white-space:pre"> </span>/************************************************************************/
<span style="white-space:pre"> </span>/*<span style="white-space:pre"> </span>2.联网:得到serverID */
<span style="white-space:pre"> </span>/************************************************************************/
<span style="white-space:pre"> </span>m_nCurrentServerID = 16;
<span style="white-space:pre"> </span>m_nServerTotalNum = 31; <span style="white-space:pre"> </span>//创建登录UI层
<span style="white-space:pre"> </span>UILayer* pLoginUiLayer = UILayer::create();
<span style="white-space:pre"> </span>CC_BREAK_IF(pLoginUiLayer==NULL); <span style="white-space:pre"> </span>UILayout *pLoginWidget = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("NormalLogin.json"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pLoginWidget==NULL);
<span style="white-space:pre"> </span>pLoginUiLayer->addWidget(pLoginWidget);
<span style="white-space:pre"> </span>pLoginWidget->setName("LoginLayer");
<span style="white-space:pre"> </span>pLoginWidget->setSize(getContentSize()); <span style="white-space:pre"> </span>addChild(pLoginUiLayer,enZOrderBack,enTagStudioLoginLayer); <span style="white-space:pre"> </span>//设置切换serverbutton回调
<span style="white-space:pre"> </span>UIButton* pBtn_Server_Select = dynamic_cast<UIButton*>(pLoginWidget->getChildByName("MainUi")->getChildByName("Btn_Change_Server"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pBtn_Server_Select==NULL);
<span style="white-space:pre"> </span>pBtn_Server_Select->addTouchEventListener(this,toucheventselector(CNFLoginScene::OnBtnServerSelectCallBack)); <span style="white-space:pre"> </span>/************************************************************************/
<span style="white-space:pre"> </span>/*<span style="white-space:pre"> </span>背景图片 */
<span style="white-space:pre"> </span>/************************************************************************/
<span style="white-space:pre"> </span>////创建背景图片
<span style="white-space:pre"> </span>//CCSprite * pServerSelectBg = CCSprite::create("ui/serverselect_bg.png");
<span style="white-space:pre"> </span>//CC_BREAK_IF(pServerSelectBg==NULL);
<span style="white-space:pre"> </span>//pServerSelectBg->setScaleX( (float)CCDirector::sharedDirector()->getWinSize().width/(float)pServerSelectBg->getContentSize().width );
<span style="white-space:pre"> </span>//pServerSelectBg->setPosition(SCREEN_CENTER);
<span style="white-space:pre"> </span>//addChild(pServerSelectBg,enZOrderBack); <span style="white-space:pre"> </span>////创建logo图片
<span style="white-space:pre"> </span>//CCSprite * pName = CCSprite::create("ui/logo_bg.png");
<span style="white-space:pre"> </span>//CC_BREAK_IF(pName==NULL);
<span style="white-space:pre"> </span>//pName->setPosition(ccp(SCREEN_WIDTH*0.5f,350));
<span style="white-space:pre"> </span>//addChild(pName,enZOrderBack); <span style="white-space:pre"> </span>////创建server名称背景
<span style="white-space:pre"> </span>//CCScale9Sprite * pServerNameBg = CCScale9Sprite::create("ui/bg_1.png");
<span style="white-space:pre"> </span>//CC_BREAK_IF(pServerNameBg==NULL);
<span style="white-space:pre"> </span>//pServerNameBg->setContentSize(CCSizeMake(173,40));
<span style="white-space:pre"> </span>//pServerNameBg->setPosition(ccp(SCREEN_WIDTH*0.5f,220));
<span style="white-space:pre"> </span>//addChild(pServerNameBg,enZOrderBack); <span style="white-space:pre"> </span>/************************************************************************/
<span style="white-space:pre"> </span>/*<span style="white-space:pre"> </span>创建button */
<span style="white-space:pre"> </span>/************************************************************************/
<span style="white-space:pre"> </span>//CCMenu * pMenu = CCMenu::create();
<span style="white-space:pre"> </span>//CC_BREAK_IF(pMenu==NULL);
<span style="white-space:pre"> </span>//pMenu->setPosition(CCPointZero);
<span style="white-space:pre"> </span>//addChild(pMenu,enZOrderMid); <span style="white-space:pre"> </span>////选择serverbutton
<span style="white-space:pre"> </span>//CCMenuItemSprite * pBtnServerSelect = CCMenuItemSprite::create(
<span style="white-space:pre"> </span>//<span style="white-space:pre"> </span>CCSprite::create("ui/btn_enter_n.png"),
<span style="white-space:pre"> </span>//<span style="white-space:pre"> </span>CCSprite::create("ui/btn_enter_p.png"),
<span style="white-space:pre"> </span>//<span style="white-space:pre"> </span>this,
<span style="white-space:pre"> </span>//<span style="white-space:pre"> </span>menu_selector(CNFLoginScene::OnBtnServerSelectCallBack));
<span style="white-space:pre"> </span>//CC_BREAK_IF(pBtnServerSelect==NULL);
<span style="white-space:pre"> </span>//pBtnServerSelect->setScaleY(0.8f);
<span style="white-space:pre"> </span>//pBtnServerSelect->setScaleX(0.2f);
<span style="white-space:pre"> </span>//pBtnServerSelect->setPosition(ccp(pServerNameBg->getPositionX() + 63 ,pServerNameBg->getPositionY()));
<span style="white-space:pre"> </span>//pMenu->addChild(pBtnServerSelect,enZOrderFront); <span style="white-space:pre"> </span>/************************************************************************/
<span style="white-space:pre"> </span>/*<span style="white-space:pre"> </span>label */
<span style="white-space:pre"> </span>/************************************************************************/
<span style="white-space:pre"> </span>//CCDictionary *pDicLang = CCDictionary::createWithContentsOfFile("ui_xml/serverselect_xml.xml");
<span style="white-space:pre"> </span>//CC_BREAK_IF(pDicLang==NULL); <span style="white-space:pre"> </span>////serverlabel
<span style="white-space:pre"> </span>//CCString *pStrServer = dynamic_cast<CCString*>(pDicLang->objectForKey("server"));
<span style="white-space:pre"> </span>//CCLabelTTF * pLabelServer = CCLabelTTF::create(pStrServer->m_sString.c_str(),"Arial",20);
<span style="white-space:pre"> </span>//CC_BREAK_IF(pLabelServer==NULL);
<span style="white-space:pre"> </span>//pLabelServer->setPosition(ccp(pServerNameBg->getPositionX() - 120,pServerNameBg->getPositionY()));
<span style="white-space:pre"> </span>//pLabelServer->setColor(ccBLACK);
<span style="white-space:pre"> </span>//addChild(pLabelServer,enZOrderFront); <span style="white-space:pre"> </span>////server名称label
<span style="white-space:pre"> </span>//CCString *pStrServerName = dynamic_cast<CCString*>(pDicLang->objectForKey("server_name"));
<span style="white-space:pre"> </span>//char szName[NAME_LEN] = {0};
<span style="white-space:pre"> </span>//sprintf(szName,pStrServerName->m_sString.c_str(),m_nCurrentServerID);
<span style="white-space:pre"> </span>//CCLabelTTF * pLabelServerName = CCLabelTTF::create(szName,"Arial",20);
<span style="white-space:pre"> </span>//CC_BREAK_IF(pLabelServerName==NULL);
<span style="white-space:pre"> </span>//pLabelServerName->setPosition(ccp(pServerNameBg->getPositionX() - 20,pServerNameBg->getPositionY()));
<span style="white-space:pre"> </span>//addChild(pLabelServerName,enZOrderFront,enTagServerNameLabel); <span style="white-space:pre"> </span>////切换label
<span style="white-space:pre"> </span>//CCString *pStrChange = dynamic_cast<CCString*>(pDicLang->objectForKey("server_change"));
<span style="white-space:pre"> </span>//CCLabelTTF * pLabelChange = CCLabelTTF::create(pStrChange->m_sString.c_str(),"Arial",15);
<span style="white-space:pre"> </span>//CC_BREAK_IF(pLabelChange==NULL);
<span style="white-space:pre"> </span>//pLabelChange->setPosition(pBtnServerSelect->getPosition());
<span style="white-space:pre"> </span>//addChild(pLabelChange,enZOrderFront); <span style="white-space:pre"> </span>
#if(NF_PLATFORM == NF_PLATFORM_NORMAL)//没接SDK版 这里调用的是前面的公共的 <span style="white-space:pre"> </span>//隐藏SDK登录模块
<span style="white-space:pre"> </span>UILayout* pSdk_Login_Panel = dynamic_cast<UILayout*>(pLoginWidget->getChildByName("MainUi")->getChildByName("Sdk_Login_Panel"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pSdk_Login_Panel==NULL);
<span style="white-space:pre"> </span>pSdk_Login_Panel->setEnabled(false);
<span style="white-space:pre"> </span>pSdk_Login_Panel->setVisible(false); <span style="white-space:pre"> </span>//显示正常登录模块
<span style="white-space:pre"> </span>UILayout* pNormalLogin_Panel = dynamic_cast<UILayout*>(pLoginWidget->getChildByName("MainUi")->getChildByName("NormalLogin_Panel"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pNormalLogin_Panel==NULL);
<span style="white-space:pre"> </span>pNormalLogin_Panel->setEnabled(true);
<span style="white-space:pre"> </span>pNormalLogin_Panel->setVisible(true); <span style="white-space:pre"> </span>//设置注冊button回调
<span style="white-space:pre"> </span>UIButton* pBtn_Register = dynamic_cast<UIButton*>(pLoginWidget->getChildByName("MainUi")->getChildByName("NormalLogin_Panel")->getChildByName("Btn_rg"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pBtn_Register==NULL);
<span style="white-space:pre"> </span>pBtn_Register->addTouchEventListener(this,toucheventselector(CNFLoginScene::OnBtnSwitchToRegisterCallBack)); <span style="white-space:pre"> </span>//设置登录button回调
<span style="white-space:pre"> </span>UIButton* pBtn_Login = dynamic_cast<UIButton*>(pLoginWidget->getChildByName("MainUi")->getChildByName("NormalLogin_Panel")->getChildByName("Btn_Log"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pBtn_Login==NULL);
<span style="white-space:pre"> </span>pBtn_Login->addTouchEventListener(this,toucheventselector(CNFLoginScene::OnBtnLoginCallBack)); <span style="white-space:pre"> </span>//设置注冊button回调
<span style="white-space:pre"> </span>UITextField* pAccount_TextField = dynamic_cast<UITextField*>(pLoginWidget->getChildByName("MainUi")->getChildByName("NormalLogin_Panel")->getChildByName("Account_TextField"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pAccount_TextField==NULL);
<span style="white-space:pre"> </span>pAccount_TextField->setTouchSize(CCSizeMake(161,30));
<span style="white-space:pre"> </span>pAccount_TextField->didNotSelectSelf(); #else <span style="white-space:pre"> </span>////进入游戏button
<span style="white-space:pre"> </span>//CCMenuItemSprite * pBtnEnter = CCMenuItemSprite::create(
<span style="white-space:pre"> </span>//<span style="white-space:pre"> </span>CCSprite::create("ui/btn_enter_n.png"),
<span style="white-space:pre"> </span>//<span style="white-space:pre"> </span>CCSprite::create("ui/btn_enter_p.png"),
<span style="white-space:pre"> </span>//<span style="white-space:pre"> </span>this,
<span style="white-space:pre"> </span>//<span style="white-space:pre"> </span>menu_selector(CNFLoginScene::OnBtnEnterCallBack));
<span style="white-space:pre"> </span>//CC_BREAK_IF(pBtnEnter==NULL);
<span style="white-space:pre"> </span>//pBtnEnter->setPosition(ccp(SCREEN_WIDTH*0.5f,140));
<span style="white-space:pre"> </span>//pMenu->addChild(pBtnEnter,enZOrderFront); <span style="white-space:pre"> </span>////进入游戏label
<span style="white-space:pre"> </span>//CCString *pStrStart = dynamic_cast<CCString*>(pDicLang->objectForKey("start"));
<span style="white-space:pre"> </span>//CCLabelTTF * pLabelStart = CCLabelTTF::create(pStrStart->m_sString.c_str(),"Arial",20);
<span style="white-space:pre"> </span>//CC_BREAK_IF(pLabelStart==NULL);
<span style="white-space:pre"> </span>//pLabelStart->setPosition(pBtnEnter->getPosition());
<span style="white-space:pre"> </span>//addChild(pLabelStart,enZOrderFront); <span style="white-space:pre"> </span>//设置进入游戏button回调
<span style="white-space:pre"> </span>UIButton* pBtn_SDK_Start = dynamic_cast<UIButton*>(pLoginWidget->getChildByName("MainUi")->getChildByName("Sdk_Login_Panel")->getChildByName("Btn_SDK_Start"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pBtn_SDK_Start==NULL);
<span style="white-space:pre"> </span>pBtn_SDK_Start->addTouchEventListener(this,toucheventselector(CNFLoginScene::OnBtnEnterCallBack));<span style="white-space:pre"> </span> #endif <span style="white-space:pre"> </span>return ;
<span style="white-space:pre"> </span>} while (false);
<span style="white-space:pre"> </span>CCLog("Fun CNFLoginScene::InitSceneUI Error!");
} void CNFLoginScene::OnBtnEnterCallBack( 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>////人物选择场景
<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>//人物选择场景
<span style="white-space:pre"> </span>CCScene * pScene = CNFTeamCreateLayer::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("Fun CNFLoginScene::OnBtnEnterCallBack Error!");
} void CNFLoginScene::OnBtnServerSelectCallBack( 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>//创建切换server层
<span style="white-space:pre"> </span>CNFServerChangeLayer * pLayer = CNFServerChangeLayer::CreateLayer(m_nCurrentServerID,m_nServerTotalNum);
<span style="white-space:pre"> </span>CC_BREAK_IF(pLayer==NULL);
<span style="white-space:pre"> </span>pLayer->SetMsg(this);
<span style="white-space:pre"> </span>addChild(pLayer,enZOrderFront+100); <span style="white-space:pre"> </span>//创建登录UI层
<span style="white-space:pre"> </span>UILayer* pLoginUiLayer = dynamic_cast<UILayer*>(getChildByTag(enTagStudioLoginLayer));
<span style="white-space:pre"> </span>CC_BREAK_IF(pLoginUiLayer==NULL); <span style="white-space:pre"> </span>UILayout *pNormalLogin = dynamic_cast<UILayout*>(pLoginUiLayer->getWidgetByName("LoginLayer"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pNormalLogin==NULL); <span style="white-space:pre"> </span>//显示正常登录模块
<span style="white-space:pre"> </span>UILayout* pNormalLogin_Panel = dynamic_cast<UILayout*>(pNormalLogin->getChildByName("MainUi")->getChildByName("NormalLogin_Panel"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pNormalLogin_Panel==NULL);
<span style="white-space:pre"> </span>pNormalLogin_Panel->setEnabled(false);
<span style="white-space:pre"> </span>pNormalLogin_Panel->setVisible(false); <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("Fun CNFLoginScene::OnBtnServerSelectCallBack Error!");
} void CNFLoginScene::RecMsg( int nMsgID,void* pInfo,int nSize )
{
<span style="white-space:pre"> </span>switch (nMsgID)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>case enMsg_ServerSelect:
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>tagServerSelect * pCmd = (tagServerSelect *)pInfo; <span style="white-space:pre"> </span>m_nCurrentServerID = pCmd->nServerID; <span style="white-space:pre"> </span>//创建登录UI层
<span style="white-space:pre"> </span>UILayer* pLoginUiLayer = dynamic_cast<UILayer*>(getChildByTag(enTagStudioLoginLayer));
<span style="white-space:pre"> </span>CC_BREAK_IF(pLoginUiLayer==NULL); <span style="white-space:pre"> </span>UILayout *pLoginWidget = dynamic_cast<UILayout*>(pLoginUiLayer->getWidgetByName("LoginLayer"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pLoginWidget==NULL); <span style="white-space:pre"> </span>//server名称label
<span style="white-space:pre"> </span>CCDictionary *pDicLang = CCDictionary::createWithContentsOfFile("ui_xml/serverselect_xml.xml");
<span style="white-space:pre"> </span>CC_BREAK_IF(pDicLang==NULL);
<span style="white-space:pre"> </span>CCString *pStrServerName = dynamic_cast<CCString*>(pDicLang->objectForKey("server_name")); <span style="white-space:pre"> </span>char szName[NAME_LEN] = {0};
<span style="white-space:pre"> </span>sprintf(szName,pStrServerName->m_sString.c_str(),m_nCurrentServerID); <span style="white-space:pre"> </span>UILabel* pServer_Name_Lable = dynamic_cast<UILabel*>(pLoginWidget->getChildByName("MainUi")->getChildByName("Server_Bg")->getChildByName("Server_Name_Lable"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pServer_Name_Lable==NULL); <span style="white-space:pre"> </span>pServer_Name_Lable->setText(szName); <span style="white-space:pre"> </span>//显示正常登录模块
<span style="white-space:pre"> </span>UILayout* pNormalLogin_Panel = dynamic_cast<UILayout*>(pLoginWidget->getChildByName("MainUi")->getChildByName("NormalLogin_Panel"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pNormalLogin_Panel==NULL);
<span style="white-space:pre"> </span>pNormalLogin_Panel->setEnabled(true);
<span style="white-space:pre"> </span>pNormalLogin_Panel->setVisible(true); <span style="white-space:pre"> </span>}break;
<span style="white-space:pre"> </span>}
} void CNFLoginScene::OnBtnSwitchToRegisterCallBack( 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>//创建登录UI层
<span style="white-space:pre"> </span>UILayer* pRegisterUiLayer = UILayer::create();
<span style="white-space:pre"> </span>CC_BREAK_IF(pRegisterUiLayer==NULL); <span style="white-space:pre"> </span>UILayout *pRegisterWidget = dynamic_cast<UILayout*>(GUIReader::shareReader()->widgetFromJsonFile("NormalRegister.json"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pRegisterWidget==NULL);
<span style="white-space:pre"> </span>pRegisterUiLayer->addWidget(pRegisterWidget);
<span style="white-space:pre"> </span>pRegisterWidget->setName("RegistLayer");
<span style="white-space:pre"> </span>pRegisterWidget->setSize(getContentSize()); <span style="white-space:pre"> </span>//设置返回登录button回调
<span style="white-space:pre"> </span>UIButton* pBtn_Back = dynamic_cast<UIButton*>(pRegisterWidget->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(CNFLoginScene::OnBackToLoginCallBack)); <span style="white-space:pre"> </span>//注冊button回调
<span style="white-space:pre"> </span>UIButton* pBtn_rg = dynamic_cast<UIButton*>(pRegisterWidget->getChildByName("MainUi")->getChildByName("NormalRegister_Panel")->getChildByName("Btn_rg"));
<span style="white-space:pre"> </span>CC_BREAK_IF(pBtn_rg==NULL);
<span style="white-space:pre"> </span>pBtn_rg->addTouchEventListener(this,toucheventselector(CNFLoginScene::OnBtnRegisterCallBack)); <span style="white-space:pre"> </span>addChild(pRegisterUiLayer,enZOrderBack,enTagStudioRegisterLayer); <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("Fun CNFLoginScene::OnBtnRegisterCallBack Error!");
} void CNFLoginScene::OnBtnLoginCallBack( 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>//读取角色信息
<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->nState>=0)
<span style="white-space:pre"> </span>{
<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>return;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>//人物选择场景
<span style="white-space:pre"> </span>CCScene * pScene = CNFTeamCreateLayer::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("Fun CNFLoginScene::OnBtnLoginCallBack Error!");
} void CNFLoginScene::OnAccountTextFieldEvent( CCObject *pSender, TextFiledEventType type )
{
<span style="white-space:pre"> </span>do
<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>注冊模块<span style="white-space:pre"> </span>*/
/************************************************************************/ void CNFLoginScene::OnBackToLoginCallBack( 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>removeChildByTag(enTagStudioRegisterLayer); <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("Fun CNFLoginScene::OnBackToLoginCallBack Error!");
} void CNFLoginScene::OnBtnRegisterCallBack( 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>CCLog("CNFLoginScene::OnBtnRegisterCallBack"); <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("Fun CNFLoginScene::OnBtnRegisterCallBack Error!");
}
因为这一款游戏的server代码不公开 没办法分析 但是,现有的点代码已经够我分析
版权声明:本文博客原创文章,博客,未经同意,不得转载。
分析Cocos2d-x横版ACT手游源 1、登录的更多相关文章
- 分析Cocos2d-x横版ACT手游源码 1、公共
直接上代码 不说什么 这一款源码 凝视及多 PublicDef.h 公共头文件 #define NF_PLATFORM 1 //当前版本号(默觉得普通版) //版本号列表 #define NF_PLA ...
- 分析Cocos2d-x横版ACT手游源 2、server场景
仍然一样 直接在代码 资源 下一个 上传 你可以看到自己 NFServerChangeLayer.h </pre><pre name="code" class=& ...
- Unity3D手游-横版ACT游戏完整源代码下载
说明: 这不是武林.这不是江湖,没有道不完的恩怨,没有斩不断的情仇,更没有理不清的烦恼,这是剑的世界,一代剑魁闯入未知世界,将会为这个世界展开什么样的蓝图.让你来创造它的未来,剑魁道天下,一剑斗烛龙! ...
- 出售一套Unity ARPG手游源码
项目已经上线,在越南App Store曾经排名第一.客户端Unity C#开发,Android可以热更新,IOS可以更新资源,服务器 C++ + lua开发,文档齐全,欢迎咨询. QQ:7734952 ...
- 转载:手游安全破“黑”行动:向黑产业链说NO
目前的手游市场已被称为红海.从业界认为的2013年的“手游元年”至今,手游发展可谓是既经历了市场的野蛮生长,也有百家争鸣的战国时代.如今,手游市场竞争已趋白热化,增长放缓.但移动互联网的发展大势之下, ...
- 2019十大安卓手游折扣平台app排行榜
2019游戏版号陆续开放,玩家又有许多好游戏可以玩了. 小编就以当前最热门的十个游戏来点评手游折扣平台App排行榜吧! 排名第一的游戏: 少年西游记-新征程 老平台,集成SDK,良心平台,覆盖全网游戏 ...
- 爆料:2019手游折扣app是真福利还是骗人哪个靠谱?
直接上干货.也许你在找寻,安全的手游折扣App,稳定的手游折扣App,不断续充的折扣App,续充不涨价的折扣App,网上的内容太多,难以分辨.那么看这个可以直接给你答案 1.历史(2004年成立,15 ...
- 手游折扣app排行榜前10名_2018哪个折扣app最低最好
2018游戏圈白皮书发布,PC端游的份额继续下降,页游的比例也在下降,但手游的比例持续3年上升.以渠道为阵营,逐渐小的平台和公会被逐渐淘汰.流量集中在少数几个大的平台.但是这样带来的问题是,平台越来越 ...
- UWA发布 | 2017 Unity手游体检蓝皮书 — ARPG篇
报告目录: 一.ARPG手游总体性能开销分析 二.ARPG手游CPU模块性能开销分析 三.ARPG手游内存模块性能开销分析 四.ARPG手游资源管理分析 五.UWA对于ARPG手游研发团队的建议 一. ...
随机推荐
- 如何去除ecshop标题和网站底部的Powered by ECShop
这个问题困扰大家很久了,感觉Powered by ECShop出现在网站里边不爽,想方设法无法去除.今天在下专门把解决方法贴出来,希望能够方便大家! 注:我们使用ecshop的产品,建议把网站底部的P ...
- HUNNU11351:Pythagoras's Revenge
http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11351&courseid=0 Problem des ...
- zigbee学习:示例程序SampleApp中按键工作流程
zigbee学习:示例程序SampleApp中按键工作流程 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 环境: 主机:WIN7 开发环境:IAR8. ...
- 无法打开登录所请求的数据库 "ASPState"。登录失败。 用户 'NT AUTHORITY/SYSTEM' 登录失败。
原文:无法打开登录所请求的数据库 "ASPState".登录失败. 用户 'NT AUTHORITY/SYSTEM' 登录失败. 无法打开登录 'ASPState' 中请求的数据库 ...
- 通过 HTTP 头进行 SQL 注入(转)
英文原文:DatabaseTube,翻译:开源中国 在漏洞评估和渗透测试中,确定目标应用程序的输入向量是第一步.这篇文章解释了别人是如何通过HTTP头部对你的数据库进行SQL注入攻击的,以及讨论下选择 ...
- Kinect的学习笔记发展(一)Kinect引进和应用
Kinect的学习笔记发展(一)Kinect引进和应用 zouxy09@qq.com http://blog.csdn.net/zouxy09 一.Kinect简单介绍 Kinectfor Xbox ...
- Emacs经常使用快捷键的注意事项
一直用VIM,尝试了好几次Emacs都被它"多得像天上的星星"一样的快捷键给吓倒了.这几天最终下定决心再次尝试. 将它的Tutor练习了一下,顺便对经常使用快捷键做了一下笔记,方便 ...
- siwft初学(一)
今天刚開始学习swift语言.首先须要下载xcode6 beta版本号.正式版本号然后会公布.自己学习总结一下,假设有误.请大家指出. 创建project的时候.language选择swift语言. ...
- Cocos2d-X在SwitchControl使用
SwitchControl控制类中的一个开关的发挥了作用似在现实生活中开关 因为控制相对简单,我没有做过多的解释.直接在代码 首先在project文件夹下的Resource文件夹中加入三张图片 在Sw ...
- Hive自己定义函数的使用——useragent解析
想要从日志数据中分析一下操作系统.浏览器.版本号使用情况.可是hive中的函数不能直接解析useragent,于是能够写一个UDF来解析.useragent用于表示用户的当前操作系统,浏览器版本号信息 ...