• <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>

            專(zhuān)職C++

            不能停止的腳步

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

            常用鏈接

            留言簿(28)

            我參與的團(tuán)隊(duì)

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            cocos2dx框架已經(jīng)提供了很多場(chǎng)景切換的類(lèi),但是一些自定義的場(chǎng)景切換,只有自己實(shí)現(xiàn)了。下面是實(shí)現(xiàn)的類(lèi)。這里設(shè)計(jì)的分辨率是750*500.請(qǐng)根據(jù)實(shí)際的要求調(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;
                    //設(shè)置左邊的起點(diǎn)和終點(diǎn)
                    stLeftBegin.setPoint(-436.0f, -60);
                    stLeftEnd.setPoint(visibleSize.width / 2.0f + stLeftBegin.x, -60.0f);
                    //設(shè)置右邊的起點(diǎn)和終點(diǎn)
                    stRightBegin.setPoint(visibleSize.width, -60.0f);
                    stRightEnd.setPoint(visibleSize.width / 2.0f, -60.0f);
                    //加載動(dòng)畫(huà)序列
                    CCSpriteFrameCache* pCache = CCSpriteFrameCache::sharedSpriteFrameCache();
                    pCache->addSpriteFramesWithFile("middle_ani_1.plist");
                    pCache->addSpriteFramesWithFile("middle_ani_2.plist");
                    //生成畫(huà)動(dòng)圖片列表和動(dòng)畫(huà)對(duì)象
                    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(); //這個(gè)有兩個(gè)子節(jié)點(diǎn),一個(gè)是左邊交換圖片,一個(gè)是中間的動(dòng)畫(huà),用于一起做移動(dòng)的Action
                    CCSprite* pLeft = CCSprite::createWithSpriteFrameName("swap_left.png");
                    pLeft->setAnchorPoint(CCPointZero);
                    pNode->addChild(pLeft);

                    CCSprite * pMiddle = CCSprite::create();  //顯示動(dòng)畫(huà)
                    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);

                    //定義動(dòng)作
                    
            //左邊的向右移動(dòng)活動(dòng)
                    CCMoveTo* pActionLeft = CCMoveTo::create(m_fDuration / 3, stLeftEnd);
                    //右邊的向左移動(dòng)活動(dòng)
                    CCMoveTo * pActionRight = CCMoveTo::create(m_fDuration / 3, stRightEnd);
                    //原地不動(dòng)
                    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)
                {
                    //所以的活動(dòng)完成后,要執(zhí)行場(chǎng)行的Finish
                    m_FinishCnt++;
                    if (m_FinishCnt >= 2)
                    {
                        CCTransitionScene::finish();
                    }
                }

                void CCTransitionGame::OnFirstActionFinish(void)
                {
                    //打開(kāi)門(mén)之前,關(guān)閉顯示第一個(gè)場(chǎng)景,顯示第二個(gè)場(chǎng)景
                    m_pInScene->setVisible(true);
                    m_pOutScene->setVisible(false);
                }

            }
            用到的資源
            /Files/zdhsoft/plist.zip 效果圖:
            posted on 2014-07-01 20:12 冬瓜 閱讀(2146) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): 原創(chuàng) 、cocos2dx
            大香伊人久久精品一区二区| 亚洲国产精品综合久久一线| 精品久久久久久国产潘金莲| 麻豆AV一区二区三区久久| 久久精品国产只有精品2020| 精品久久久久中文字幕一区| 亚洲午夜精品久久久久久浪潮 | 国产精品99久久久久久www| 久久精品国产黑森林| 久久久久高潮毛片免费全部播放| 久久精品国产72国产精福利| 精品国产99久久久久久麻豆| 99热热久久这里只有精品68| 久久久久高潮综合影院| 国产精自产拍久久久久久蜜| 久久久噜噜噜久久中文字幕色伊伊 | 一本大道久久东京热无码AV | 99久久免费国产特黄| 欧美一区二区久久精品| 亚洲天堂久久精品| 久久AV高清无码| 热99RE久久精品这里都是精品免费| 久久99国产精品久久| 亚洲国产一成人久久精品| 色婷婷综合久久久久中文字幕| 久久成人精品视频| 国内精品久久人妻互换| 欧美一区二区三区久久综| 欧美国产成人久久精品| 久久99精品久久久久久秒播| 久久国产乱子伦精品免费强| 性做久久久久久久| 久久久亚洲欧洲日产国码是AV| 亚洲欧美国产日韩综合久久 | 久久久久人妻精品一区| 久久久久免费精品国产| 性做久久久久久久久| 久久嫩草影院免费看夜色| 久久久无码精品亚洲日韩软件| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久久精品久久久久特色影视|