• <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)的類。這里設(shè)計的分辨率是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;
                    //設(shè)置左邊的起點和終點
                    stLeftBegin.setPoint(-436.0f, -60);
                    stLeftEnd.setPoint(visibleSize.width / 2.0f + stLeftBegin.x, -60.0f);
                    //設(shè)置右邊的起點和終點
                    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 冬瓜 閱讀(2151) 評論(0)  編輯 收藏 引用 所屬分類: 原創(chuàng)cocos2dx
            久久99国产精一区二区三区| 久久久久九九精品影院| 久久久久成人精品无码中文字幕| 午夜欧美精品久久久久久久| 国产三级久久久精品麻豆三级| 女人香蕉久久**毛片精品| 伊人热热久久原色播放www| 久久九九精品99国产精品| 久久午夜无码鲁丝片午夜精品| 亚洲色婷婷综合久久| 国产91久久综合| 久久精品国产一区| 亚洲中文久久精品无码| 久久黄视频| 久久这里只有精品久久| 亚洲va久久久噜噜噜久久狠狠| 久久精品视屏| 久久99久久无码毛片一区二区| 久久久久女人精品毛片| 久久精品日日躁夜夜躁欧美| 久久电影网| 久久高清一级毛片| 岛国搬运www久久| 久久国产精品-国产精品| 久久人人爽人人爽人人AV东京热| 久久亚洲精品无码VA大香大香| 久久伊人色| 三级片免费观看久久| 久久久精品人妻无码专区不卡| 国产精品99久久精品爆乳| 久久久久久狠狠丁香| 51久久夜色精品国产| 国产精品热久久毛片| 99久久综合狠狠综合久久| 日韩一区二区久久久久久| 国产成人综合久久久久久| 国产精品九九久久免费视频| 久久www免费人成精品香蕉| 日本精品久久久久影院日本 | 四虎国产精品成人免费久久| 久久人人爽人人精品视频|