• <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)
                {
                    //打開門之前,關(guān)閉顯示第一個場景,顯示第二個場景
                    m_pInScene->setVisible(true);
                    m_pOutScene->setVisible(false);
                }

            }
            用到的資源
            /Files/zdhsoft/plist.zip 效果圖:
            posted on 2014-07-01 20:12 冬瓜 閱讀(2146) 評論(0)  編輯 收藏 引用 所屬分類: 原創(chuàng)cocos2dx
            国产色综合久久无码有码| 99久久无色码中文字幕人妻| 国产精品久久久久久一区二区三区| 亚洲欧美伊人久久综合一区二区 | 久久国产视屏| 久久精品国产99国产精品亚洲 | 久久精品国产一区二区三区不卡| 日韩久久久久中文字幕人妻| 亚洲国产精品无码成人片久久| 国产精品免费福利久久| 激情五月综合综合久久69| 18禁黄久久久AAA片| 成人妇女免费播放久久久| 亚洲国产成人精品久久久国产成人一区二区三区综 | 伊人久久大香线蕉综合热线| 久久久久久久人妻无码中文字幕爆 | 欧美黑人又粗又大久久久| 久久99精品久久久久久噜噜| 亚洲中文久久精品无码| 香蕉久久影院| 人妻丰满?V无码久久不卡| 久久综合综合久久狠狠狠97色88| 少妇人妻综合久久中文字幕| 精品久久久久久久久久中文字幕| 亚洲国产精品无码久久98| 久久天天躁狠狠躁夜夜2020老熟妇 | 久久99国产精品尤物| 囯产精品久久久久久久久蜜桃| 国产精品欧美亚洲韩国日本久久 | 久久精品国产网红主播| 女同久久| 日韩欧美亚洲国产精品字幕久久久| 久久久久久久99精品免费观看| 99精品国产综合久久久久五月天 | 久久久久久国产a免费观看不卡| 久久永久免费人妻精品下载| 久久人妻AV中文字幕| 久久精品免费全国观看国产| 人妻精品久久久久中文字幕| 狠狠色丁香久久婷婷综合蜜芽五月| 手机看片久久高清国产日韩|