• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            專職C++

            不能停止的腳步

              C++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              163 Posts :: 7 Stories :: 135 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(28)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            cocos2dx框架已經(jīng)提供了很多場景切換的類,但是一些自定義的場景切換,只有自己實現(xiàn)了。下面是實現(xiàn)的類。這里設計的分辨率是750*500.請根據(jù)實際的要求調(diào)整。
            頭文件
            #ifndef _TRANSITION_GAME_H_
            #define _TRANSITION_GAME_H_
            #include <cocos2d.h>
            namespace cocos2d 
            {
                class CCTransitionGame : public CCTransitionScene
                {
                public:
                    CCTransitionGame();
                    virtual ~CCTransitionGame();
                    void onEnter();
                    static CCTransitionGame * create(float t, CCScene *scene);
                private:
                    void LRFinish(void);
                    void OnFirstActionFinish(void);
                private:
                    int m_FinishCnt;
                };
            }
            #endif
            源文件
            #include "TransitionGame.h"
            #include "xlog.h"
            #include <xstring.h>
            namespace cocos2d
            {
                using namespace zdh;
                CCTransitionGame * CCTransitionGame::create(float t, CCScene *scene)
                {
                    CCTransitionGame * pScene = new CCTransitionGame();
                    if (pScene && pScene->initWithDuration(t, scene))
                    {
                        pScene->autorelease();
                        return pScene;
                    }
                    CC_SAFE_DELETE(pScene);
                    return NULL;
                }

                CCTransitionGame::CCTransitionGame()
                {
                    m_FinishCnt = 0;
                }

                CCTransitionGame::~CCTransitionGame()
                {
                }

                void CCTransitionGame::onEnter()
                {
                    CCTransitionScene::onEnter();
                    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();


                    CCPoint stLeftBegin, stLeftEnd, stRightBegin, stRightEnd;
                    //設置左邊的起點和終點
                    stLeftBegin.setPoint(-436.0f, -60);
                    stLeftEnd.setPoint(visibleSize.width / 2.0f + stLeftBegin.x, -60.0f);
                    //設置右邊的起點和終點
                    stRightBegin.setPoint(visibleSize.width, -60.0f);
                    stRightEnd.setPoint(visibleSize.width / 2.0f, -60.0f);
                    //加載動畫序列
                    CCSpriteFrameCache* pCache = CCSpriteFrameCache::sharedSpriteFrameCache();
                    pCache->addSpriteFramesWithFile("middle_ani_1.plist");
                    pCache->addSpriteFramesWithFile("middle_ani_2.plist");
                    //生成畫動圖片列表和動畫對象
                    CCArray* pAnimFrames = CCArray::createWithCapacity(69);
                    XAnsiString strAniName;
                    for (int i = 1; i < 70; i++)
                    {
                        strAniName.printf("light%04d.png", i);
                        pAnimFrames->addObject(pCache->spriteFrameByName(strAniName.c_str()));
                    }
                    CCAnimation* animation = CCAnimation::createWithSpriteFrames(pAnimFrames, this->m_fDuration * 2.0f/3.0f/69.0f );
                    

                    CCNode * pNode = CCNode::create(); //這個有兩個子節(jié)點,一個是左邊交換圖片,一個是中間的動畫,用于一起做移動的Action
                    CCSprite* pLeft = CCSprite::createWithSpriteFrameName("swap_left.png");
                    pLeft->setAnchorPoint(CCPointZero);
                    pNode->addChild(pLeft);

                    CCSprite * pMiddle = CCSprite::create();  //顯示動畫
                    pMiddle->setAnchorPoint(CCPointZero);
                    pMiddle->setPosition(ccp(436.0f - 69.0f, 250.0f + 60.0f - 72.0f));
                    pMiddle->runAction(CCAnimate::create(animation));
                    pNode->addChild(pMiddle);

                    pNode->setAnchorPoint(ccp(0,0));
                    pNode->setPosition(stLeftBegin);
                    this->addChild(pNode,1);

                    //右邊的交換圖片
                    CCSprite* pRight = CCSprite::createWithSpriteFrameName("swap_right.png");
                    pRight->setPosition(stRightBegin);
                    pRight->setAnchorPoint(CCPointZero);
                    this->addChild(pRight, 0);

                    //定義動作
                    
            //左邊的向右移動活動
                    CCMoveTo* pActionLeft = CCMoveTo::create(m_fDuration / 3, stLeftEnd);
                    //右邊的向左移動活動
                    CCMoveTo * pActionRight = CCMoveTo::create(m_fDuration / 3, stRightEnd);
                    //原地不動
                    CCMoveTo* pActionLeft1 = CCMoveTo::create(m_fDuration / 3, stLeftEnd);
                    CCMoveTo * pActionRight1 = CCMoveTo::create(m_fDuration / 3, stRightEnd);
                    
                    CCMoveTo* pActionLeft2 = CCMoveTo::create(m_fDuration / 3, stLeftBegin);
                    CCMoveTo * pActionRight2 = CCMoveTo::create(m_fDuration / 3, stRightBegin);

                    m_FinishCnt = 0;
                    pNode->runAction(CCSequence::create(pActionLeft, CCCallFunc::create(this, callfunc_selector(CCTransitionGame::OnFirstActionFinish)), pActionLeft1, pActionLeft2, CCCallFunc::create(this, callfunc_selector(CCTransitionGame::LRFinish)), NULL));
                    pRight->runAction(CCSequence::create(pActionRight, pActionRight1,pActionRight2, CCCallFunc::create(this, callfunc_selector(CCTransitionGame::LRFinish)), NULL));
                }

                void CCTransitionGame::LRFinish(void)
                {
                    //所以的活動完成后,要執(zhí)行場行的Finish
                    m_FinishCnt++;
                    if (m_FinishCnt >= 2)
                    {
                        CCTransitionScene::finish();
                    }
                }

                void CCTransitionGame::OnFirstActionFinish(void)
                {
                    //打開門之前,關閉顯示第一個場景,顯示第二個場景
                    m_pInScene->setVisible(true);
                    m_pOutScene->setVisible(false);
                }

            }
            用到的資源
            /Files/zdhsoft/plist.zip 效果圖:
            posted on 2014-07-01 20:12 冬瓜 閱讀(2151) 評論(0)  編輯 收藏 引用 所屬分類: 原創(chuàng)cocos2dx
            亚洲精品午夜国产va久久| 亚洲AV乱码久久精品蜜桃| 久久综合久久自在自线精品自 | 久久久久亚洲AV无码去区首| 久久久综合九色合综国产| 久久国产香蕉视频| 99久久精品免费看国产一区二区三区| 久久亚洲日韩精品一区二区三区| .精品久久久麻豆国产精品| 久久国产成人精品国产成人亚洲| 狠狠综合久久综合88亚洲| 99久久www免费人成精品| 欧美久久久久久| 国产精品成人精品久久久 | 91精品国产91久久| 亚洲乱码精品久久久久.. | 噜噜噜色噜噜噜久久| 久久香蕉综合色一综合色88| 久久精品国产亚洲AV蜜臀色欲| 97久久精品午夜一区二区| 77777亚洲午夜久久多喷| 日韩久久无码免费毛片软件| 色成年激情久久综合| 久久久久久国产精品无码超碰| 久久只这里是精品66| 一本久久精品一区二区| 亚洲综合婷婷久久| 国产欧美久久久精品| 久久人妻少妇嫩草AV无码专区 | 国产成人精品久久亚洲| 粉嫩小泬无遮挡久久久久久| 日韩人妻无码精品久久久不卡| 国产免费久久精品99re丫y| 欧美久久亚洲精品| 武侠古典久久婷婷狼人伊人| 久久久久国产日韩精品网站| 久久国产免费直播| 久久久久久av无码免费看大片| 国内精品久久久久久久亚洲| 999久久久免费国产精品播放| 久久综合久久久|