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

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

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            [cocos2dx筆記002] 坦克動畫
            第一:沒有美術(shù),只好自己用PS。先用PS在原來的4個(gè)方向上,做一個(gè)履帶差異的4方向坦克。
            第二:用SpritePacker打包成tankbase.plist。然后用CCSpriteFrameCache加載到內(nèi)存中。
            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>
            第三:封裝一個(gè)動畫的函數(shù)
                    /********************************************************************************
                      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
                    {
                        //創(chuàng)建幀資源的數(shù)組
                        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);

                        //創(chuàng)建動畫對象 第二個(gè)參數(shù)是每幀間隔時(shí)間 這里是0.1秒
                        CCAnimation * pAni = CCAnimation::createWithSpriteFrames(st_frame_list, 0.1f);
                        //創(chuàng)建動畫Action
                        CCAnimate * pAniAction = CCAnimate::create(pAni);
                        //創(chuàng)建重復(fù)Action
                        CCRepeatForever *pAction = CCRepeatForever::create(pAniAction);
                        
                        st_frame_list->release();
                        return pAction;
                    }
            第四:在玩家對象設(shè)置方向和對象初始化的時(shí)候,設(shè)置動畫
            初始化:
                        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);
            設(shè)置方向:
                    /********************************************************************************
                      Title: 設(shè)置坦克的方向
                     
                      FullName:   zdh::XPlayer::setDirection
                      Access:     public 
                      @param [in] paramDirection 如果是無效的方向,會視為ED_UP
                      @return     bool 
                        - true   設(shè)置成功
                        - false  設(shè)置失敗
                      @author     zdhsoft
                      @date       2014/03/24
                      @file       xplayer.h
                     *******************************************************************************
            */
                    bool setDirection(const int paramDirection)
                    {
                        if (paramDirection >= ED_UP &&paramDirection <= ED_RIGHT)  //如果是無效方向,則設(shè)置不成功
                        {
                            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 冬瓜 閱讀(1415) 評論(1)  編輯 收藏 引用 所屬分類: 原創(chuàng)cocos2dx

            Feedback

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

            磁芯大戰(zhàn)造嗎  回復(fù)  更多評論
              

            久久AAAA片一区二区| 久久精品无码一区二区无码| 久久综合久久综合久久| 日本免费久久久久久久网站| 久久er国产精品免费观看8| 久久久久亚洲av综合波多野结衣| 久久精品aⅴ无码中文字字幕不卡| 国产精品久久久久久影院| 久久国产精品一区| 久久亚洲欧美国产精品 | 久久久久这里只有精品 | 亚洲午夜久久久久久久久久 | 久久久人妻精品无码一区 | 国产午夜精品理论片久久 | 国产精品免费久久久久久久久| 青青草国产97免久久费观看| 成人久久精品一区二区三区| 性做久久久久久久久浪潮| 日本免费久久久久久久网站| 久久综合噜噜激激的五月天| 亚洲国产天堂久久久久久| 精品国产青草久久久久福利| 国产精品久久久久久久久鸭 | 亚洲精品无码久久久影院相关影片| 久久93精品国产91久久综合| 99热成人精品热久久669| 亚洲va久久久噜噜噜久久狠狠 | 日韩av无码久久精品免费| 久久中文字幕视频、最近更新| 91亚洲国产成人久久精品网址 | 蜜桃麻豆WWW久久囤产精品| 国产精品gz久久久| 国产精品久久久99| 国产精品欧美久久久久无广告 | 久久久久亚洲AV无码专区体验| 国内精品久久久久久久久电影网| 天天影视色香欲综合久久| 人妻无码久久精品| 亚洲国产精品狼友中文久久久| 一本大道久久东京热无码AV| 久久精品一本到99热免费|