仍然一样 直接在代码   资源  下一个  上传  你可以看到自己
NFServerChangeLayer.h
</pre><pre name="code" class="cpp">/************************************************************************/
/* 服务器切换层 */
/************************************************************************/
class CNFServerChangeLayer : public CCLayer , public CMsgReceiver ,public CMsgSender
{
protected:
//标签
enum
{
enTagScrollLayer = 1,
}; int m_nCurrentServerID; public:
static CNFServerChangeLayer * CreateLayer(int nCurrentServerID,int nServerTotalNum); //当前服务器ID。服务器总数量 //消息接收
virtual void RecMsg(int nMsgID,void* pInfo,int nSize); protected:
virtual bool InitLayer(int nCurrentServerID,int nServerTotalNum); //button回调:返回
void OnBtnCallBack(CCObject * pObj);
//button回调:向左滑动
void OnBtnLeftMove(CCObject * pObj);
//button回调:向右滑动
void OnBtnRightMove(CCObject * pObj);
}; #endif
<span style="white-space:pre">	</span>.cpp文件
#include "NFServerChangeLayer.h"
#include "NFServerChangeScrollLayer.h" CNFServerChangeLayer * CNFServerChangeLayer::CreateLayer(int nCurrentServerID,int nServerTotalNum)
{
<span style="white-space:pre"> </span>CNFServerChangeLayer *pRet = new CNFServerChangeLayer();
<span style="white-space:pre"> </span>if (pRet && pRet->InitLayer(nCurrentServerID,nServerTotalNum))
<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 CNFServerChangeLayer::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 CNFServerChangeLayer::InitLayer(int nCurrentServerID,int nServerTotalNum)
{
<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_nCurrentServerID = nCurrentServerID; <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 * pBg = CCSprite::create("ui/serverselect_bg.png");
<span style="white-space:pre"> </span>CC_BREAK_IF(pBg==NULL);
<span style="white-space:pre"> </span>pBg->setPosition(SCREEN_CENTER);
<span style="white-space:pre"> </span>pBg->setScaleX( (float)CCDirector::sharedDirector()->getWinSize().width/(float)pBg->getContentSize().width );
<span style="white-space:pre"> </span>addChild(pBg,enZOrderBack); <span style="white-space:pre"> </span>//创建上次登录图片
<span style="white-space:pre"> </span>CCSprite * pBg1 = CCSprite::create("ui/serverselect_title_1.png");
<span style="white-space:pre"> </span>CC_BREAK_IF(pBg1==NULL);
<span style="white-space:pre"> </span>pBg1->setPosition(ccp(150+_NF_SCREEN_WIDTH_DIS_,420));
<span style="white-space:pre"> </span>addChild(pBg1,enZOrderBack); <span style="white-space:pre"> </span>//创建全服务器图片
<span style="white-space:pre"> </span>CCSprite * pBg2 = CCSprite::create("ui/serverselect_title_2.png");
<span style="white-space:pre"> </span>CC_BREAK_IF(pBg2==NULL);
<span style="white-space:pre"> </span>pBg2->setPosition(ccp(160+_NF_SCREEN_WIDTH_DIS_,300));
<span style="white-space:pre"> </span>addChild(pBg2,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,enZOrderFront); <span style="white-space:pre"> </span>//创建返回button
<span style="white-space:pre"> </span>//CCMenuItemSprite * pBtnBack = CCMenuItemSprite::create(
<span style="white-space:pre"> </span>//<span style="white-space:pre"> </span>CCSprite::create("ui/serverselect_btn_back_n.png"),
<span style="white-space:pre"> </span>//<span style="white-space:pre"> </span>CCSprite::create("ui/serverselect_btn_back_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(CNFServerChangeLayer::OnBtnCallBack));
<span style="white-space:pre"> </span>//CC_BREAK_IF(pBtnBack==NULL);
<span style="white-space:pre"> </span>//pBtnBack->setPosition(ccp(SCREEN_WIDTH - 30,SCREEN_HEIGHT-30));
<span style="white-space:pre"> </span>//pMenu->addChild(pBtnBack,enZOrderFront); <span style="white-space:pre"> </span>//创建当前服务器button
<span style="white-space:pre"> </span>CCMenuItemSprite * pBtnCurrentServer = CCMenuItemSprite::create(
<span style="white-space:pre"> </span>CCSprite::create("ui/btn_enter_n.png"),
<span style="white-space:pre"> </span>CCSprite::create("ui/btn_enter_p.png"),
<span style="white-space:pre"> </span>this,
<span style="white-space:pre"> </span>menu_selector(CNFServerChangeLayer::OnBtnCallBack));
<span style="white-space:pre"> </span>CC_BREAK_IF(pBtnCurrentServer==NULL);
<span style="white-space:pre"> </span>pBtnCurrentServer->setPosition(ccp(190+_NF_SCREEN_WIDTH_DIS_,380));
<span style="white-space:pre"> </span>pMenu->addChild(pBtnCurrentServer,enZOrderFront); <span style="white-space:pre"> </span>//创建左側button
<span style="white-space:pre"> </span>CCMenuItemSprite * pBtnLeft = CCMenuItemSprite::create(
<span style="white-space:pre"> </span>CCSprite::create("ui/serverselect_btn_back_n.png"),
<span style="white-space:pre"> </span>CCSprite::create("ui/serverselect_btn_back_p.png"),
<span style="white-space:pre"> </span>this,
<span style="white-space:pre"> </span>menu_selector(CNFServerChangeLayer::OnBtnLeftMove));
<span style="white-space:pre"> </span>CC_BREAK_IF(pBtnLeft==NULL);
<span style="white-space:pre"> </span>pBtnLeft->setPosition(ccp(50+_NF_SCREEN_WIDTH_DIS_,150));
<span style="white-space:pre"> </span>pMenu->addChild(pBtnLeft,enZOrderFront); <span style="white-space:pre"> </span>//创建右側button
<span style="white-space:pre"> </span>CCMenuItemSprite * pBtnRight = CCMenuItemSprite::create(
<span style="white-space:pre"> </span>CCSprite::create("ui/serverselect_btn_back_n.png"),
<span style="white-space:pre"> </span>CCSprite::create("ui/serverselect_btn_back_p.png"),
<span style="white-space:pre"> </span>this,
<span style="white-space:pre"> </span>menu_selector(CNFServerChangeLayer::OnBtnRightMove));
<span style="white-space:pre"> </span>CC_BREAK_IF(pBtnRight==NULL);
<span style="white-space:pre"> </span>pBtnRight->setPosition(ccp(SCREEN_WIDTH-_NF_SCREEN_WIDTH_DIS_-50,150));
<span style="white-space:pre"> </span>pMenu->addChild(pBtnRight,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 *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(),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(pBtnCurrentServer->getPosition());
<span style="white-space:pre"> </span>addChild(pLabelServerName,enZOrderFront); <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>CNFServerChangeScrollLayer * pLayer = CNFServerChangeScrollLayer::CreateLayer(nServerTotalNum);<span style="white-space:pre"> </span>//Item数组。x轴起始位置
<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,enTagScrollLayer); <span style="white-space:pre"> </span>return true;
<span style="white-space:pre"> </span>} while (false);
<span style="white-space:pre"> </span>CCLog("Fun CNFServerChangeLayer::init Error!");
<span style="white-space:pre"> </span>return false;
} //button回调:返回
void CNFServerChangeLayer::OnBtnCallBack( CCObject * pObj )
{
<span style="white-space:pre"> </span>//发消息:更改服务器
<span style="white-space:pre"> </span>tagServerSelect Info;
<span style="white-space:pre"> </span>Info.nServerID = m_nCurrentServerID;
<span style="white-space:pre"> </span>SendMsg(enMsg_ServerSelect,&Info,sizeof(Info)); <span style="white-space:pre"> </span>//移除自身
<span style="white-space:pre"> </span>removeFromParentAndCleanup(true);
} //button回调:向左滑动
void CNFServerChangeLayer::OnBtnLeftMove( CCObject * pObj )
{
<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>CNFServerChangeScrollLayer * pLayer = dynamic_cast<CNFServerChangeScrollLayer *>(getChildByTag(enTagScrollLayer));
<span style="white-space:pre"> </span>CC_BREAK_IF(pLayer==NULL);
<span style="white-space:pre"> </span>pLayer->SetRightMove(); <span style="white-space:pre"> </span>return ;
<span style="white-space:pre"> </span>} while (false);
<span style="white-space:pre"> </span>CCLog("Fun CNFServerChangeLayer::OnBtnLeftMove Error!");
} //button回调:向右滑动
void CNFServerChangeLayer::OnBtnRightMove( CCObject * pObj )
{
<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>CNFServerChangeScrollLayer * pLayer = dynamic_cast<CNFServerChangeScrollLayer *>(getChildByTag(enTagScrollLayer));
<span style="white-space:pre"> </span>CC_BREAK_IF(pLayer==NULL);
<span style="white-space:pre"> </span>pLayer->SetLeftMove(); <span style="white-space:pre"> </span>return ;
<span style="white-space:pre"> </span>} while (false);
<span style="white-space:pre"> </span>CCLog("Fun CNFServerChangeLayer::OnBtnRightMove Error!");
} //消息接收
void CNFServerChangeLayer::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>//发消息:更改服务器
<span style="white-space:pre"> </span>tagServerSelect Info;
<span style="white-space:pre"> </span>Info.nServerID = pCmd->nServerID; <span style="white-space:pre"> </span>SendMsg(enMsg_ServerSelect,&Info,sizeof(Info)); <span style="white-space:pre"> </span>//移除自身
<span style="white-space:pre"> </span>removeFromParentAndCleanup(true); <span style="white-space:pre"> </span>}break;
<span style="white-space:pre"> </span>}
} NFServerChangeScrollLayer.h 文件
/************************************************************************/
/*<span style="white-space:pre"> </span>服务器选择界面,滑动层                                                                     */
/************************************************************************/
class CNFServerChangeScrollLayer : public CCLayerColor ,public CMsgSender
{
protected:
<span style="white-space:pre"> </span>// 标签
<span style="white-space:pre"> </span>enum
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>enTagMenu = 1,
<span style="white-space:pre"> </span>enTagBtn = 100,
<span style="white-space:pre"> </span>}; <span style="white-space:pre"> </span>float<span style="white-space:pre"> </span>m_fTouchPassPosX;<span style="white-space:pre"> </span>//上一次计算触摸时。手指滑过的位置
<span style="white-space:pre"> </span>float<span style="white-space:pre"> </span>m_fTouchBeginPosX;<span style="white-space:pre"> </span>//用户触摸最初始的位置
<span style="white-space:pre"> </span>bool<span style="white-space:pre"> </span>m_bTouching;<span style="white-space:pre"> </span>//是否取消了触摸(保证不会反复调用TouchEnd)
<span style="white-space:pre"> </span>bool<span style="white-space:pre"> </span>m_bIsTouchBtn;<span style="white-space:pre"> </span>//是否触摸到button <span style="white-space:pre"> </span>float<span style="white-space:pre"> </span>m_fPageWidth;<span style="white-space:pre"> </span>//每一页的宽度
<span style="white-space:pre"> </span>float<span style="white-space:pre"> </span>m_fEndLayerPos;<span style="white-space:pre"> </span>//结束边界的位置
<span style="white-space:pre"> </span>float<span style="white-space:pre"> </span>m_fStartNodePosX;<span style="white-space:pre"> </span>//初始节点x轴位置 <span style="white-space:pre"> </span>CCRect<span style="white-space:pre"> </span>m_DisPlayRect;<span style="white-space:pre"> </span>//显示区域 public:
<span style="white-space:pre"> </span>static CNFServerChangeScrollLayer* CreateLayer(int nItemNum); <span style="white-space:pre"> </span>//向左滑
<span style="white-space:pre"> </span>void SetLeftMove(); <span style="white-space:pre"> </span>//向右滑
<span style="white-space:pre"> </span>void SetRightMove(); protected:
<span style="white-space:pre"> </span>bool InitLayer(int nItemNum); <span style="white-space:pre"> </span>//设置裁剪区域
<span style="white-space:pre"> </span>void visit(); <span style="white-space:pre"> </span>//触摸函数
<span style="white-space:pre"> </span>virtual bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
<span style="white-space:pre"> </span>virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
<span style="white-space:pre"> </span>virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
<span style="white-space:pre"> </span>virtual void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent); <span style="white-space:pre"> </span>//button回调
<span style="white-space:pre"> </span>void OnBtnCallBack(CCObject * pObj); <span style="white-space:pre"> </span>virtual void onExit(); }; #endif
#include "NFServerChangeScrollLayer.h"

#define _ONE_PAGE_SERVER_NUM_<span style="white-space:pre">	</span>12<span style="white-space:pre">		</span>//每一页所拥有的服务器的个数
#define _X_START_POS_<span style="white-space:pre"> </span>78<span style="white-space:pre"> </span>//x轴初始坐标
#define _PAGE_WIDTH_<span style="white-space:pre"> </span>564<span style="white-space:pre"> </span>//页面宽度
#define _PAGE_HEIGHT_<span style="white-space:pre"> </span>285<span style="white-space:pre"> </span>//页面高度 /************************************************************************/
/*<span style="white-space:pre"> </span>滑动层                                                  */
/************************************************************************/
CNFServerChangeScrollLayer* CNFServerChangeScrollLayer::CreateLayer(int nItemNum)
{<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>CNFServerChangeScrollLayer *pRet = new CNFServerChangeScrollLayer();
<span style="white-space:pre"> </span>if (pRet && pRet->InitLayer(nItemNum))
<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>CC_SAFE_DELETE(pRet);
<span style="white-space:pre"> </span>return NULL;
} bool CNFServerChangeScrollLayer::InitLayer(int nItemNum)
{<span style="white-space:pre"> </span>
<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(CCLayerColor::initWithColor(ccc4(0,0,0,0))==false); <span style="white-space:pre"> </span>//独占触屏注冊值小于-128才干屏蔽Menu(Menu默认是-128)
<span style="white-space:pre"> </span>CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, -129, true); <span style="white-space:pre"> </span>//初始x轴坐标
<span style="white-space:pre"> </span>m_fStartNodePosX = _X_START_POS_ + _NF_SCREEN_WIDTH_DIS_; ;<span style="white-space:pre"> </span>//页面数量
<span style="white-space:pre"> </span>int nPageNum = nItemNum%_ONE_PAGE_SERVER_NUM_ > 0 ? nItemNum/_ONE_PAGE_SERVER_NUM_+1 : nItemNum/_ONE_PAGE_SERVER_NUM_; <span style="white-space:pre"> </span>//每一页宽度
<span style="white-space:pre"> </span>m_fPageWidth = _PAGE_WIDTH_; <span style="white-space:pre"> </span>//页面高度
<span style="white-space:pre"> </span>float<span style="white-space:pre"> </span>fPageHeight = _PAGE_HEIGHT_; <span style="white-space:pre"> </span>//x轴最小坐标
<span style="white-space:pre"> </span>m_fEndLayerPos = m_fPageWidth*(1-nPageNum); <span style="white-space:pre"> </span>//x。y轴之间的间隔
<span style="white-space:pre"> </span>float fItemDisX = 11;
<span style="white-space:pre"> </span>float fItemDisY = 20; <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>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>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,enZOrderFront,enTagMenu); <span style="white-space:pre"> </span>//创建数组
<span style="white-space:pre"> </span>CCObject *pObj = NULL;
<span style="white-space:pre"> </span>for (int k=1;k<=nItemNum;k++)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>int i = k%_ONE_PAGE_SERVER_NUM_ > 0 ? k%_ONE_PAGE_SERVER_NUM_ : _ONE_PAGE_SERVER_NUM_;<span style="white-space:pre"> </span>//页面内ITem的ID:1~12
<span style="white-space:pre"> </span>int j = k%_ONE_PAGE_SERVER_NUM_ > 0 ? k/_ONE_PAGE_SERVER_NUM_+1 : k/_ONE_PAGE_SERVER_NUM_;<span style="white-space:pre"> </span>//当前页面ID <span style="white-space:pre"> </span>int nCrossNum = i%3 == 0 ? 3 : i%3;<span style="white-space:pre"> </span>//横排
<span style="white-space:pre"> </span>int nVerticalNum = i%3 > 0 ? i/3+1 : i/3;<span style="white-space:pre"> </span>//竖排 <span style="white-space:pre"> </span>//创建button
<span style="white-space:pre"> </span>CCMenuItemSprite * pBtn = CCMenuItemSprite::create(
<span style="white-space:pre"> </span>CCSprite::create("ui/btn_enter_n.png"),
<span style="white-space:pre"> </span>CCSprite::create("ui/btn_enter_p.png"),
<span style="white-space:pre"> </span>this,
<span style="white-space:pre"> </span>menu_selector(CNFServerChangeScrollLayer::OnBtnCallBack));
<span style="white-space:pre"> </span>CC_BREAK_IF(pBtn==NULL);
<span style="white-space:pre"> </span>pBtn->setPosition(ccp( fItemDisX+ (nCrossNum-1)*(pBtn->getContentSize().width+fItemDisX) + m_fStartNodePosX + pBtn->getContentSize().width*0.5f + (j-1)*m_fPageWidth , fPageHeight-nVerticalNum*(pBtn->getContentSize().height+fItemDisY) + fItemDisY ));
<span style="white-space:pre"> </span>pMenu->addChild(pBtn,enZOrderFront,enTagBtn+k); <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(),k);
<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(pBtn->getPosition());
<span style="white-space:pre"> </span>addChild(pLabelServerName,enZOrderFront);
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>//显示区域
<span style="white-space:pre"> </span>m_DisPlayRect = CCRectMake(m_fStartNodePosX ,10 ,m_fPageWidth,fPageHeight); <span style="white-space:pre"> </span>m_bTouching = false;
<span style="white-space:pre"> </span>m_bIsTouchBtn = false; <span style="white-space:pre"> </span>return true;
<span style="white-space:pre"> </span>} while (false);
<span style="white-space:pre"> </span>CCLog("Fun CQXPVEItemScrollLayer::initWithNodes Error!");
<span style="white-space:pre"> </span>return false; } //触摸:開始
bool CNFServerChangeScrollLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
<span style="white-space:pre"> </span>CCPoint ptTouchPoint =pTouch->getLocation(); <span style="white-space:pre"> </span>//设置初始触摸点
<span style="white-space:pre"> </span>m_fTouchPassPosX = ptTouchPoint.x;
<span style="white-space:pre"> </span>m_fTouchBeginPosX = ptTouchPoint.x; <span style="white-space:pre"> </span>//推断是否触摸到裁切区域内
<span style="white-space:pre"> </span>if(m_DisPlayRect.containsPoint(ptTouchPoint))
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>m_bTouching = true; <span style="white-space:pre"> </span>//推断是否触摸到button
<span style="white-space:pre"> </span>CCMenu *pMenu = dynamic_cast<CCMenu*>(getChildByTag(enTagMenu));
<span style="white-space:pre"> </span>if(pMenu!=NULL)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>CCArray *pChildren = pMenu->getChildren();
<span style="white-space:pre"> </span>if(pChildren!=NULL)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>CCObject *pItem=NULL;
<span style="white-space:pre"> </span>CCARRAY_FOREACH(pChildren,pItem)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>CCMenuItemSprite *pBtn= dynamic_cast<CCMenuItemSprite*>(pItem);
<span style="white-space:pre"> </span>if(pBtn!=NULL)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>CCPoint local = pBtn->convertToNodeSpace(pTouch->getLocation());
<span style="white-space:pre"> </span>CCRect r = pBtn->rect();
<span style="white-space:pre"> </span>r.origin = CCPointZero;
<span style="white-space:pre"> </span>if (r.containsPoint(local))
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>pMenu->ccTouchBegan(pTouch,pEvent);
<span style="white-space:pre"> </span>m_bIsTouchBtn=true;
<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>return true;<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>return false;
} //触摸:移动
void CNFServerChangeScrollLayer::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent)
{<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>if(m_bTouching==false)return; <span style="white-space:pre"> </span>CCPoint ptTouchPoint =pTouch->getLocation();
<span style="white-space:pre"> </span>CCPoint pNewPos=getPosition(); <span style="white-space:pre"> </span>//移动层
<span style="white-space:pre"> </span>pNewPos.x+=ptTouchPoint.x-m_fTouchPassPosX;
<span style="white-space:pre"> </span>this->setPosition(pNewPos); <span style="white-space:pre"> </span>//重置初始点
<span style="white-space:pre"> </span>m_fTouchPassPosX=ptTouchPoint.x; <span style="white-space:pre"> </span>//若触摸到button
<span style="white-space:pre"> </span>if (m_bIsTouchBtn==true)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>CCMenu *pMenu = dynamic_cast<CCMenu*>(getChildByTag(enTagMenu));
<span style="white-space:pre"> </span>if (pMenu!=NULL)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>pMenu->ccTouchCancelled(pTouch,pEvent);
<span style="white-space:pre"> </span>m_bIsTouchBtn = false;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
} //触摸:结束
void CNFServerChangeScrollLayer::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
<span style="white-space:pre"> </span>if(m_bTouching==false)return; <span style="white-space:pre"> </span>m_bTouching = false; <span style="white-space:pre"> </span>CCPoint ptTouchPoint =pTouch->getLocation();
<span style="white-space:pre"> </span>CCPoint ptMyPos = getPosition(); <span style="white-space:pre"> </span>//推断移到哪一页
<span style="white-space:pre"> </span>float fDisX = ptTouchPoint.x - m_fTouchBeginPosX;
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>//判定滑动
<span style="white-space:pre"> </span>if ( _NF_ABS(fDisX)>= 20)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>//向左滑动
<span style="white-space:pre"> </span>if (fDisX < 0)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>//若未过界
<span style="white-space:pre"> </span>if (getPositionX() > m_fEndLayerPos)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>int fLen = (int)getPositionX()%(int)m_fPageWidth;
<span style="white-space:pre"> </span>ptMyPos.x = (int)( getPositionX() - fLen - m_fPageWidth);
<span style="white-space:pre"> </span>CCAction *pMoveTo=CCMoveTo::create(0.3f,ptMyPos);
<span style="white-space:pre"> </span>runAction(pMoveTo);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>//向右滑
<span style="white-space:pre"> </span>if (fDisX > 0)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>//若未过界
<span style="white-space:pre"> </span>if (getPositionX() < 0)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>int fLen = (int)getPositionX()%(int)m_fPageWidth;
<span style="white-space:pre"> </span>ptMyPos.x = (int)( getPositionX() - fLen);
<span style="white-space:pre"> </span>CCAction *pMoveTo=CCMoveTo::create(0.3f,ptMyPos);
<span style="white-space:pre"> </span>runAction(pMoveTo);
<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>if (getPositionX()>0)
<span style="white-space:pre"> </span>{<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>ptMyPos.x = 0;
<span style="white-space:pre"> </span>CCAction *pMoveTo=CCMoveTo::create(0.3f,ptMyPos);
<span style="white-space:pre"> </span>runAction(pMoveTo);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>else if (getPositionX()<m_fEndLayerPos)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>ptMyPos.x = m_fEndLayerPos<0?m_fEndLayerPos:0;
<span style="white-space:pre"> </span>CCAction *pMoveTo=CCMoveTo::create(0.3f,ptMyPos);
<span style="white-space:pre"> </span>runAction(pMoveTo);
<span style="white-space:pre"> </span>} <span style="white-space:pre"> </span>//滑动层,当前坐标
<span style="white-space:pre"> </span>CCPoint LayerPos;
<span style="white-space:pre"> </span>LayerPos.x = getPositionX();
<span style="white-space:pre"> </span>LayerPos.y = getPositionY(); <span style="white-space:pre"> </span>//若触摸到button
<span style="white-space:pre"> </span>if (m_bIsTouchBtn==true)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>CCMenu *pMenu = dynamic_cast<CCMenu*>(getChildByTag(enTagMenu));
<span style="white-space:pre"> </span>if (pMenu!=NULL)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>pMenu->ccTouchEnded(pTouch,pEvent);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>m_bIsTouchBtn = false;
<span style="white-space:pre"> </span>} } void CNFServerChangeScrollLayer::ccTouchCancelled( CCTouch *pTouch, CCEvent *pEvent )
{
<span style="white-space:pre"> </span>m_bTouching = false;
} //裁切
void CNFServerChangeScrollLayer::visit()
{
<span style="white-space:pre"> </span>kmGLPushMatrix(); <span style="white-space:pre"> </span>if (m_pGrid && m_pGrid->isActive())
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>m_pGrid->beforeDraw();
<span style="white-space:pre"> </span>this->transformAncestors();
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>this->transform(); <span style="white-space:pre"> </span>glEnable(GL_SCISSOR_TEST); <span style="white-space:pre"> </span>CCSize size=CCEGLView::sharedOpenGLView()->getFrameSize(); <span style="white-space:pre"> </span>float fScaleX=size.width/SCREEN_WIDTH;
<span style="white-space:pre"> </span>float fScaleY=size.height/SCREEN_HEIGHT; <span style="white-space:pre"> </span>glScissor(m_DisPlayRect.origin.x*fScaleX,m_DisPlayRect.origin.y*fScaleY,m_DisPlayRect.size.width*fScaleX,m_DisPlayRect.size.height*fScaleY); <span style="white-space:pre"> </span>if (m_pChildren)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>for (unsigned int i=0;i<m_pChildren->data->num;i++)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>CCNode* pNode=(CCNode*)m_pChildren->data->arr[i];
<span style="white-space:pre"> </span>if (pNode->getZOrder()<0)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>pNode->visit();
<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>break;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>draw();
<span style="white-space:pre"> </span>for (unsigned int i=0;i<m_pChildren->data->num;i++)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>CCNode* pNode=(CCNode*)m_pChildren->data->arr[i];
<span style="white-space:pre"> </span>pNode->visit();
<span style="white-space:pre"> </span>}
<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>draw();
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>glDisable(GL_SCISSOR_TEST);
<span style="white-space:pre"> </span>if (m_pGrid &&m_pGrid->isActive())
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>m_pGrid->afterDraw(this);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>kmGLPopMatrix();
} //button回调
void CNFServerChangeScrollLayer::OnBtnCallBack( CCObject * pObj )
{
<span style="white-space:pre"> </span>do 
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>int nTag = (dynamic_cast<CCMenuItemSprite *>(pObj))->getTag(); <span style="white-space:pre"> </span>//发消息:更改服务器
<span style="white-space:pre"> </span>tagServerSelect Info;
<span style="white-space:pre"> </span>Info.nServerID = nTag-100; <span style="white-space:pre"> </span>//发消息,切换服务器
<span style="white-space:pre"> </span>SendMsg(enMsg_ServerSelect,&Info,sizeof(Info)); <span style="white-space:pre"> </span>//移除自身
<span style="white-space:pre"> </span>removeFromParentAndCleanup(true);
<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 CNFServerSelectScrollLayer::OnBtnCallBack Error!");
} void CNFServerChangeScrollLayer::onExit()
{
<span style="white-space:pre"> </span>//取消独占
<span style="white-space:pre"> </span>CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this); <span style="white-space:pre"> </span>CCLayer::onExit();
} void CNFServerChangeScrollLayer::SetLeftMove()
{
<span style="white-space:pre"> </span>//若当前未触摸
<span style="white-space:pre"> </span>if (m_bTouching==false)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>//若未过界
<span style="white-space:pre"> </span>if (getPositionX() > m_fEndLayerPos)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>CCPoint ptMyPos;
<span style="white-space:pre"> </span>ptMyPos.x = (int)( getPositionX() - m_fPageWidth);
<span style="white-space:pre"> </span>CCAction *pMoveTo=CCMoveTo::create(0.3f,ptMyPos);
<span style="white-space:pre"> </span>runAction(pMoveTo);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
} void CNFServerChangeScrollLayer::SetRightMove()
{
<span style="white-space:pre"> </span>//若当前未触摸
<span style="white-space:pre"> </span>if (m_bTouching==false)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>//若未过界
<span style="white-space:pre"> </span>if (getPositionX() < 0)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>CCPoint ptMyPos;
<span style="white-space:pre"> </span>ptMyPos.x = (int)( getPositionX() + m_fPageWidth);
<span style="white-space:pre"> </span>CCAction *pMoveTo=CCMoveTo::create(0.3f,ptMyPos);
<span style="white-space:pre"> </span>runAction(pMoveTo);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
}


版权声明:本文博客原创文章,博客,未经同意,不得转载。

分析Cocos2d-x横版ACT手游源 2、server场景的更多相关文章

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

    我自己的游戏代码 因为 游戏源 盯着外面的 我们能够能够理解 /******************************************************************** ...

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

    直接上代码 不说什么 这一款源码 凝视及多 PublicDef.h 公共头文件 #define NF_PLATFORM 1 //当前版本号(默觉得普通版) //版本号列表 #define NF_PLA ...

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

    说明: 这不是武林.这不是江湖,没有道不完的恩怨,没有斩不断的情仇,更没有理不清的烦恼,这是剑的世界,一代剑魁闯入未知世界,将会为这个世界展开什么样的蓝图.让你来创造它的未来,剑魁道天下,一剑斗烛龙! ...

  4. 出售一套Unity ARPG手游源码

    项目已经上线,在越南App Store曾经排名第一.客户端Unity C#开发,Android可以热更新,IOS可以更新资源,服务器 C++ + lua开发,文档齐全,欢迎咨询. QQ:7734952 ...

  5. Unity3D手游开发日记(3) - 场景加载进度条的完美方案

    我以为做个进度条很简单,分分钟解决,结果折腾了一天才搞定,Unity有很多坑,要做完美需要逐一解决. 问题1:最简单的方法不能实现100%的进度 用最简单的方法来实现,不能实现100%的进度,原因是U ...

  6. 转载:手游安全破“黑”行动:向黑产业链说NO

    目前的手游市场已被称为红海.从业界认为的2013年的“手游元年”至今,手游发展可谓是既经历了市场的野蛮生长,也有百家争鸣的战国时代.如今,手游市场竞争已趋白热化,增长放缓.但移动互联网的发展大势之下, ...

  7. 2019十大安卓手游折扣平台app排行榜

    2019游戏版号陆续开放,玩家又有许多好游戏可以玩了. 小编就以当前最热门的十个游戏来点评手游折扣平台App排行榜吧! 排名第一的游戏: 少年西游记-新征程 老平台,集成SDK,良心平台,覆盖全网游戏 ...

  8. 爆料:2019手游折扣app是真福利还是骗人哪个靠谱?

    直接上干货.也许你在找寻,安全的手游折扣App,稳定的手游折扣App,不断续充的折扣App,续充不涨价的折扣App,网上的内容太多,难以分辨.那么看这个可以直接给你答案 1.历史(2004年成立,15 ...

  9. 手游折扣app排行榜前10名_2018哪个折扣app最低最好

    2018游戏圈白皮书发布,PC端游的份额继续下降,页游的比例也在下降,但手游的比例持续3年上升.以渠道为阵营,逐渐小的平台和公会被逐渐淘汰.流量集中在少数几个大的平台.但是这样带来的问题是,平台越来越 ...

随机推荐

  1. MSMQ学习笔记

    这几天学习了一下MSMQ,虽然不能说非常深入的了解其机制与实际用法(具体项目的实现),但也要给自己的学习做个总结.学习心得如下: 一.MSMQ即微软消息队列.用于程序之间的异步消息通信,主要的机制就是 ...

  2. 如何嗅闻交换网络和ARP骗子-ARP解释的原则

    在嗅探以太网(一般指嗅探器可以对流经的网络数据包窃听)(sniff)不为网络安全是好事,虽然网络管理员能够跟踪数据包,发现 互联网问题,但前提是,如果破坏者使用.在整个网络带来了严重的安全威胁. 至于 ...

  3. MAC OSX 进程间通信

    Mac OS在下面IPC方式很多类型,大约如下. 1. Mach API  2. CFMessagePort  3. Distributed Objects (DO) NSDistributedNot ...

  4. nginx conf by linux kernel

    #nginx conf by linux kernel net.ipv4.tcp_max_tw_buckets = 6000 net.ipv4.ip_local_port_range = 1024 6 ...

  5. Java中的逆变与协变(转)

    看下面一段代码 Number num = new Integer(1); ArrayList<Number> list = new ArrayList<Integer>(); ...

  6. HTTP协议中返回代码302的情况

    http协议中,返回状态码302表示重定向. 这样的情况下,server返回的头部信息中会包括一个 Location 字段,内容是重定向到的url

  7. SQL操作语句中的注意点

    一 查询语句 1 distinctkeyword消除反复行 当查询的结果数据中出现反复数据时.在查询条件中加上distinctkeyword消除反复行: 如:select distinct Sno f ...

  8. Xcode的小标记旁边的文件的名称的作用

    这两天老板教我要注意Xcode该文件名以小标记权.例如: 这里的M就是Xcode中类名旁边的一个symbol.还有A,D等,这些标记用于显示当前文件和代码仓库中该文件对照后的状态: M = Local ...

  9. AngularJS+ASP.NET MVC+SignalR实现消息推送

    原文:AngularJS+ASP.NET MVC+SignalR实现消息推送 背景 OA管理系统中,员工提交申请单,消息实时通知到相关人员及时进行审批,审批之后将结果推送给用户. 技术选择 最开始发现 ...

  10. C++使用简单的函数指针

    函数指针: 被调用函数指针必须包括函数的存储器地址,为了正常工作,指针还必须包括其它信息,这一参数列表指针的参数类型和返回类型的函数. 因此,当你声明一个函数指针,数的參数类型和返回类型.以及指针名. ...