• <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++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              163 Posts :: 7 Stories :: 135 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(28)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            [cocos2dx筆記002] 坦克動畫
            第一:沒有美術,只好自己用PS。先用PS在原來的4個方向上,做一個履帶差異的4方向坦克。
            第二:用SpritePacker打包成tankbase.plist。然后用CCSpriteFrameCache加載到內存中。
            CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("basetank.plist");
            <?xml version="1.0" encoding="UTF-8"?>
            <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
            <plist version="1.0">
            <dict>
                <key>frames</key>
                <dict>
                    <key>basetank_down.png</key>
                    <dict>
                        <key>frame</key>
                        <string>{{0,0},{32,32}}</string>
                        <key>offset</key>
                        <string>{0,0}</string>
                        <key>rotated</key>
                        <false/>
                        <key>sourceColorRect</key>
                        <string>{{0,0},{32,32}}</string>
                        <key>sourceSize</key>
                        <string>{32,32}</string>
                    </dict>
                    <key>basetank_down_a.png</key>
                    <dict>
                        <key>frame</key>
                        <string>{{0,132},{32,32}}</string>
                        <key>offset</key>
                        <string>{0,0}</string>
                        <key>rotated</key>
                        <false/>
                        <key>sourceColorRect</key>
                        <string>{{0,0},{32,32}}</string>
                        <key>sourceSize</key>
                        <string>{32,32}</string>
                    </dict>
                    <key>basetank_left.png</key>
                    <dict>
                        <key>frame</key>
                        <string>{{0,33},{32,32}}</string>
                        <key>offset</key>
                        <string>{0,0}</string>
                        <key>rotated</key>
                        <false/>
                        <key>sourceColorRect</key>
                        <string>{{0,0},{32,32}}</string>
                        <key>sourceSize</key>
                        <string>{32,32}</string>
                    </dict>
                    <key>basetank_left_a.png</key>
                    <dict>
                        <key>frame</key>
                        <string>{{0,165},{32,32}}</string>
                        <key>offset</key>
                        <string>{0,0}</string>
                        <key>rotated</key>
                        <false/>
                        <key>sourceColorRect</key>
                        <string>{{0,0},{32,32}}</string>
                        <key>sourceSize</key>
                        <string>{32,32}</string>
                    </dict>
                    <key>basetank_right.png</key>
                    <dict>
                        <key>frame</key>
                        <string>{{0,66},{32,32}}</string>
                        <key>offset</key>
                        <string>{0,0}</string>
                        <key>rotated</key>
                        <false/>
                        <key>sourceColorRect</key>
                        <string>{{0,0},{32,32}}</string>
                        <key>sourceSize</key>
                        <string>{32,32}</string>
                    </dict>
                    <key>basetank_right_a.png</key>
                    <dict>
                        <key>frame</key>
                        <string>{{0,198},{32,32}}</string>
                        <key>offset</key>
                        <string>{0,0}</string>
                        <key>rotated</key>
                        <false/>
                        <key>sourceColorRect</key>
                        <string>{{0,0},{32,32}}</string>
                        <key>sourceSize</key>
                        <string>{32,32}</string>
                    </dict>
                    <key>basetank_up.png</key>
                    <dict>
                        <key>frame</key>
                        <string>{{0,99},{32,32}}</string>
                        <key>offset</key>
                        <string>{0,0}</string>
                        <key>rotated</key>
                        <false/>
                        <key>sourceColorRect</key>
                        <string>{{0,0},{32,32}}</string>
                        <key>sourceSize</key>
                        <string>{32,32}</string>
                    </dict>
                    <key>basetank_up_a.png</key>
                    <dict>
                        <key>frame</key>
                        <string>{{0,231},{32,32}}</string>
                        <key>offset</key>
                        <string>{0,0}</string>
                        <key>rotated</key>
                        <false/>
                        <key>sourceColorRect</key>
                        <string>{{0,0},{32,32}}</string>
                        <key>sourceSize</key>
                        <string>{32,32}</string>
                    </dict>
                </dict>
                <key>metadata</key>
                <dict>
                    <key>format</key>
                    <integer>2</integer>
                    <key>realTextureFileName</key>
                    <string>basetank.png</string>
                    <key>size</key>
                    <string>{32,512}</string>
                    <key>smartupdate</key>
                    <string>{None}</string>
                    <key>textureFileName</key>
                    <string>basetank.png</string>
                </dict>
            </dict>
            </plist>
            第三:封裝一個動畫的函數
                    /********************************************************************************
                      Title: 生成指定方向的坦克動畫Action
                     
                      FullName:   zdh::XGameGlobal::createBasetankAni
                      Access:     public 
                      @param [in] param_Direction     方向,參見EnumDirection,如果是無效方向,視為ED_UP
                      @return     CCRepeatForever *   返回坦克動畫的Action對象
                      @author     zdhsoft
                      @date       2014/03/24
                      @file       xgameglobal.h
                     *******************************************************************************
            */
                    CCRepeatForever * createBasetankAni(int param_Direction) const
                    {
                        //創建幀資源的數組
                        CCArray* st_frame_list = new CCArray(2);
                        CCSpriteFrame * pF1 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(getDirectionResName(param_Direction, 0));
                        CCSpriteFrame * pF2 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(getDirectionResName(param_Direction, 1));
                        st_frame_list->addObject(pF1);
                        st_frame_list->addObject(pF2);

                        //創建動畫對象 第二個參數是每幀間隔時間 這里是0.1秒
                        CCAnimation * pAni = CCAnimation::createWithSpriteFrames(st_frame_list, 0.1f);
                        //創建動畫Action
                        CCAnimate * pAniAction = CCAnimate::create(pAni);
                        //創建重復Action
                        CCRepeatForever *pAction = CCRepeatForever::create(pAniAction);
                        
                        st_frame_list->release();
                        return pAction;
                    }
            第四:在玩家對象設置方向和對象初始化的時候,設置動畫
            初始化:
                        CCSprite * p1Pic = CCSprite::createWithSpriteFrameName(GAME_GLOBAL->getDirectionResName(ED_UP));
                        p1Pic->setPosition(GetPosition(pPlayerLayer, "Player1"));
                        p1Pic->setAnchorPoint(ccp(0, 0));
                        this->addChild(p1Pic);
                        p1Pic->runAction(GAME_GLOBAL->createBasetankAni(ED_UP));
                        m_Player1.setDraw(p1Pic);
            設置方向:
                    /********************************************************************************
                      Title: 設置坦克的方向
                     
                      FullName:   zdh::XPlayer::setDirection
                      Access:     public 
                      @param [in] paramDirection 如果是無效的方向,會視為ED_UP
                      @return     bool 
                        - true   設置成功
                        - false  設置失敗
                      @author     zdhsoft
                      @date       2014/03/24
                      @file       xplayer.h
                     *******************************************************************************
            */
                    bool setDirection(const int paramDirection)
                    {
                        if (paramDirection >= ED_UP &&paramDirection <= ED_RIGHT)  //如果是無效方向,則設置不成功
                        {
                            if (paramDirection != m_Direction)
                            {
                                if (m_Draw != nullptr)
                                {
                                    m_Draw->stopAllActions();
                                    m_Draw->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(GAME_GLOBAL->getDirectionResName(paramDirection)));
                                    m_Draw->runAction(GAME_GLOBAL->createBasetankAni(paramDirection));
                                }
                                m_Direction = paramDirection; //變更方向
                                return true;
                            }
                        }
                        return false;
                    }
            這樣就OK了!
            posted on 2014-03-25 00:05 冬瓜 閱讀(1409) 評論(1)  編輯 收藏 引用 所屬分類: 原創cocos2dx

            Feedback

            # re: [cocos2dx筆記002] 坦克動畫 2014-03-27 17:55 onion
            看到過這本書,不過太爛了,就沒繼續。

            磁芯大戰造嗎  回復  更多評論
              

            无码国内精品久久人妻| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 91亚洲国产成人久久精品| 94久久国产乱子伦精品免费| 91精品国产高清久久久久久国产嫩草| 国产日韩久久久精品影院首页| 久久久久久久久66精品片| 国产精品99久久免费观看| 久久久久国产成人精品亚洲午夜| 狠狠色丁香久久婷婷综合图片| www.久久热.com| 四虎国产精品成人免费久久| 久久久无码精品亚洲日韩按摩| 人人狠狠综合久久亚洲高清| 久久精品aⅴ无码中文字字幕不卡| 久久精品免费大片国产大片| 麻豆成人久久精品二区三区免费| 国内精品久久久久久久涩爱| 国产成人久久精品激情| 一级做a爰片久久毛片看看| 久久综合狠狠综合久久激情 | 久久久国产精华液| 性做久久久久久免费观看| 93精91精品国产综合久久香蕉| 久久久久亚洲精品无码蜜桃| 伊人久久大香线蕉亚洲| 伊人情人综合成人久久网小说| 99久久精品国产综合一区 | 99久久免费只有精品国产| 色狠狠久久AV五月综合| 99久久香蕉国产线看观香| 亚洲欧美精品一区久久中文字幕 | 伊人精品久久久久7777| 久久久久综合中文字幕| 国产69精品久久久久99尤物 | 日本久久久久久久久久| 久久免费视频6| 无码人妻久久一区二区三区蜜桃| 日本久久久久久中文字幕| 国产精自产拍久久久久久蜜| 国产精品女同一区二区久久|