分析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,-1,-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","xiaoyin","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",-1,-1,-1,10000);
<span style="white-space:pre">				</span>addChild(pRole,enZOrderMid,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

时间: 2024-11-06 23:26:44

分析Cocos2d-x横版ACT手游源代码 6、创建忍队界面的相关文章

分析Cocos2d-x横版ACT手游源代码 3、人物选择界面

.h文件 #ifndef _NF_ROLE_SELECT_SCENE_HEAD_ #define _NF_ROLE_SELECT_SCENE_HEAD_ #include "../publicdef/PublicDef.h" /************************************************************************/ /*人物选择层 */ /*********************************************

分析Cocos2d-x横版ACT手游源代码 1、登录

我就自己上游戏代码来 因为 这个游戏源代码 注释十分的 都可以看得懂 /************************************************************************/ /* 登录场景 */ /************************************************************************/ class CNFLoginScene : public CCLayer ,public CMsgRecei

分析Cocos2d-x横版ACT手游源代码 4、场景

.h文件 #ifndef _CM_GAME_SCENE_H_ #define _CM_GAME_SCENE_H_ #include "../publicdef/PublicDef.h" #include "../gameunit/person/NFEnemy.h" using namespace gui; class CNFGameScene : public cocos2d::CCLayer ,public CMsgReceiver { protected: //

分析Cocos2d-x横版ACT手游源代码 1、公共

直接上代码 不说什么 这一款源代码 注释及多 PublicDef.h 公共头文件 #define NF_PLATFORM 1 //当前版本(默认为普通版) //版本列表 #define NF_PLATFORM_NORMAL 1 //normal #define NF_PLATFORM_91 2 //91 playform #define NF_PLATFORM_PP 3 //PP playform #define NF_PLATFORM_UC_ANDROID 4 //UC playform #d

分析Cocos2d-x横版ACT手游源代码 5、3D世界

.h文件 #ifndef _NF_3D_WORLD_LAYER_HEAD_ #define _NF_3D_WORLD_LAYER_HEAD_ #include "../publicdef/PublicDef.h" #include "../gameunit/NFWorld3D.h" #include "../datamanager/NFEnemyWave.h" class CNF3DWorldLayer : public CNFWorld3DLa

分析Cocos2d-x横版ACT手游源代码 2、服务器场景

还是一样 直接上代码 源代码 下一篇 上传 大家可以自己看 NFServerChangeLayer.h </pre><pre name="code" class="cpp">/************************************************************************/ /* 服务器切换层 */ /***********************************************

分析Cocos2d-x横版ACT手游源 1、登录

我自己的游戏代码 因为 游戏源 盯着外面的 我们能够能够理解 /************************************************************************/ /* 登录场景 */ /************************************************************************/ class CNFLoginScene : public CCLayer ,public CMsgReceiver

Cocos2d-x三国ACT手游《热血斩将》完整源码下载

目前进度:已经完全编译完成,附带教程文档.感谢作者提供了db文件,已经可以运行. 11.png (57.76 KB, 下载次数: 0) 下载附件 三国ACT手游<热血斩将>完整源码 3 分钟前 上传 编译环境:更新 Cocos2d-x-2.2.1 更新至 2.2.6 VS2012 更新至 VS2013 Windows7 原帖请去论坛找,感谢作者的无私奉献! 为了更好的阅读代码,建议大家采用astyle工具 11.png (19.56 KB, 下载次数: 0) 下载附件 三国ACT手游<热

Unity3D手游-横版ACT游戏完整源码下载

说明: 这不是武林,这不是江湖,没有道不完的恩怨,没有斩不断的情仇,更没有理不清的烦恼,这是剑的世界,一代剑魁闯入未知世界,将会为这个世界展开什么样的蓝图,让你来创造它的未来,剑魁道天下,一剑斗烛龙!!! 游戏开发了三个月,非常值得收藏,至于做什么用途,就看你自己啦!来来来,放大招了!请看附件:) 测试环境: Unity3D 4.3.4 运行效果: 完整源码下载http://www.yxkfw.com/thread-5035-1-1.html