分析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;			//当前服务器ID
	int			m_nServerTotalNum;			//服务器的总数量

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();					//在这里加载该图层专用的资源

	//---------------登录页按钮回调----------------
	void OnBtnEnterCallBack(CCObject *pSender,TouchEventType type);			//开始游戏
	void OnBtnServerSelectCallBack(CCObject *pSender,TouchEventType type);		//选择服务器
	void OnBtnSwitchToRegisterCallBack(CCObject *pSender,TouchEventType type);	//跳转到注册页
	void OnBtnLoginCallBack(CCObject *pSender,TouchEventType type);			//登录
	void OnAccountTextFieldEvent(CCObject *pSender,TextFiledEventType type);




	//---------------注册页按钮回调----------------
	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",schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre">	</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/kulouzhanshi.ExportJson",schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre">	</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/mayi.ExportJson",schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre">	</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/bianyikunchong.ExportJson",schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre">	</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/bubing.ExportJson",schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre">	</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/xiaoyin.ExportJson",schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre">	</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/NewProject.ExportJson",schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre">	</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/minren1.ExportJson",schedule_selector(CNFLoginScene::OnLoadArmatureData));


<span style="white-space:pre">	</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/kulou_arrow.ExportJson",schedule_selector(CNFLoginScene::OnLoadArmatureData));


<span style="white-space:pre">	</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/naili.ExportJson",schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre">	</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/NPC_kakaxi.ExportJson",schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre">	</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/portal.ExportJson",schedule_selector(CNFLoginScene::OnLoadArmatureData));


<span style="white-space:pre">	</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/hited_light.ExportJson",schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre">	</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/public_casting.ExportJson",schedule_selector(CNFLoginScene::OnLoadArmatureData));
<span style="white-space:pre">	</span>CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfoAsync("armature/skill_light_1.ExportJson",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,<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,// <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.联网:得到服务器ID                                   */
<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>//设置切换服务器按钮回调
<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>////创建服务器名称背景
<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>创建按钮                                   */
<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>////选择服务器按钮
<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>////服务器label
<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>////服务器名称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,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(),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>//设置注册按钮回调
<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>//设置登录按钮回调
<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>//设置注册按钮回调
<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>////进入游戏按钮
<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>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(),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>//设置进入游戏按钮回调
<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>//创建切换服务器层
<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,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>//服务器名称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,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>//设置返回登录按钮回调
<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>//注册按钮回调
<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,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!");
}
 
 
由于这一款游戏的服务器代码没有公开  没有办法分析 但是现有点代码已经够我分析的了

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


    本文实践自 RayWenderlich、Ali Hafizji 的文章《How To Create Dynamic Textures with CCRenderTexture in Cocos2D 2.X》,文中使用Cocos2D,我在这里使用Cocos2D-x 2.1.4进行学习和移植。在这篇文章,将会学习到如何创建实时纹理、如何用Gimp创建无缝拼接纹
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@163.com微信公众号:HopToad 欢迎转载,转载标注出处:http://blog.csdn.netotbaron/article/details/424343991.  软件准备 下载地址:http://cn.cocos2d-x.org/download 2.  简介2.1         引用C
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从Cocos2D-x官网上下载,进入网页http://www.cocos2d-x.org/download,点击Cocos2d-x以下的Download  v3.0,保存到自定义的文件夹2:从python官网上下载。进入网页https://www.python.org/downloads/,我当前下载的是3.4.0(当前最新
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发引擎,易学易用,支持多种智能移动平台。官网地址:http://cocos2d-x.org/当前版本:2.0    有很多的学习资料,在这里我只做为自己的笔记记录下来,错误之处还请指出。在VisualStudio2008平台的编译:1.下载当前稳
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《最强大脑》娱乐节目。将2048改造成一款挑战玩家对数字记忆的小游戏。邮箱:appdevzw@163.com微信公众号:HopToadAPK下载地址:http://download.csdn.net/detailotbaron/8446223源码下载地址:http://download.csdn.net/
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试以QtCreatorIDE来进行CMake构建。Cocos2d-x3.X地址:https://github.com/cocos2d/cocos2d-x1.打开QtCreator,菜单栏→"打开文件或项目...",打开cocos2d-x目录下的CMakeLists.txt文件;2.弹出CMake向导,如下图所示:设置
 下载地址:链接:https://pan.baidu.com/s/1IkQsMU6NoERAAQLcCUMcXQ提取码:p1pb下载完成后,解压进入build目录使用vs2013打开工程设置平台工具集,打开设置界面设置: 点击开始编译等待编译结束编译成功在build文件下会出现一个新文件夹Debug.win32,里面就是编译
分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net前言上次用象棋演示了cocos2dx的基本用法,但是对cocos2dx并没有作深入的讨论,这次以超级马里奥的源代码为线索,我们一起来学习超级马里奥的实
1. 圆形音量button事实上作者的本意应该是叫做“电位计button”。可是我觉得它和我们的圆形音量button非常像,所以就这么叫它吧~先看效果:好了,不多解释,本篇到此为止。(旁白: 噗。就这样结束了?)啊才怪~我们来看看代码:[cpp] viewplaincopyprint?CCContro
原文链接:http://www.cnblogs.com/physwf/archive/2013/04/26/3043912.html为了进一步深入学习贯彻Cocos2d,我们将自己写一个场景类,但我们不会走的太远,凡是都要循序渐进,哪怕只前进一点点,那也至少是前进了,总比贪多嚼不烂一头雾水的好。在上一节中我们建
2019独角兽企业重金招聘Python工程师标准>>>cocos2d2.0之后加入了一种九宫格的实现,主要作用是用来拉伸图片,这样的好处在于保留图片四个角不变形的同时,对图片中间部分进行拉伸,来满足一些控件的自适应(PS: 比如包括按钮,对话框,最直观的形象就是ios里的短信气泡了),这就要求图
原文链接:http://www.cnblogs.com/linji/p/3599478.html1.环境和工具准备Win7VS2010/2012,至于2008v2版本之后似乎就不支持了。 2.安装pythonv.2.0版本之前是用vs模板创建工程的,到vs2.2之后就改用python创建了。到python官网下载版本2.7.5的,然后
环境:ubuntu14.04adt-bundle-linux-x86_64android-ndk-r9d-linux-x86_64cocos2d-x-3.0正式版apache-ant1.9.3python2.7(ubuntu自带)加入环境变量exportANDROID_SDK_ROOT=/home/yangming/adt-bundle-linux/sdkexportPATH=${PATH}:/$ANDROID_SDK_ROOTools/export
1开发背景游戏程序设计涉及了学科中的各个方面,鉴于目的在于学习与进步,本游戏《FlappyBird》采用了两个不同的开发方式来开发本款游戏,一类直接采用win32底层API来实现,另一类采用当前火热的cocos2d-x游戏引擎来开发本游戏。2需求分析2.1数据分析本项目要开发的是一款游
原文链接:http://www.cnblogs.com/linji/p/3599912.html//纯色色块控件(锚点默认左下角)CCLayerColor*ccc=CCLayerColor::create(ccc4(255,0,0,128),200,100);//渐变色块控件CCLayerGradient*ccc=CCLayerGradient::create(ccc4(255,0,0,
原文链接:http://www.cnblogs.com/linji/p/3599488.html//载入一张图片CCSprite*leftDoor=CCSprite::create("loading/door.png");leftDoor->setAnchorPoint(ccp(1,0.5));//设置锚点为右边中心点leftDoor->setPosition(ccp(240,160));/
为了答谢广大学员对智捷课堂以及关老师的支持,现购买51CTO学院关老师的Cocos2d-x课程之一可以送智捷课堂编写图书一本(专题可以送3本)。一、Cocos2d-x课程列表:1、Cocos2d-x入门与提高视频教程__Part22、Cocos2d-x数据持久化与网络通信__Part33、Cocos2d-x架构设计与性能优化内存优
Spawn让多个action同时执行。Spawn有多种不同的create方法,最终都调用了createWithTwoActions(FiniteTimeAction*action1,FiniteTimeAction*action2)方法。createWithTwoActions调用initWithTwoActions方法:对两个action变量初始化:_one=action1;_two=action2;如果两个a
需要环境:php,luajit.昨天在cygwin上安装php和luajit环境,这真特么是一个坑。建议不要用虚拟环境安装打包环境,否则可能会出现各种莫名问题。折腾了一下午,最终将环境转向linux。其中,luajit的安装脚本已经在quick-cocos2d-x-develop/bin/中,直接luajit_install.sh即可。我的lin
v3.0相对v2.2来说,最引人注意的。应该是对触摸层级的优化。和lambda回调函数的引入(嗯嗯,不枉我改了那么多类名。话说,每次cocos2dx大更新。总要改掉一堆类名函数名)。这些特性应该有不少人研究了,所以今天说点跟图片有关的东西。v3.0在载入图片方面也有了非常大改变,仅仅只是