<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        cocos2dx進階學習之屏幕適配

        來源:懂視網 責編:小采 時間:2020-11-09 07:43:32
        文檔

        cocos2dx進階學習之屏幕適配

        cocos2dx進階學習之屏幕適配:http://blog.csdn.net/itcastcpp/article/details/18608437 背景 在學習cocos2dx時,我們在main函數中發現一句代碼, [cpp] view plaincopyprint #includemain.h #includeAppDelegate.h #includeCCEGLVie
        推薦度:
        導讀cocos2dx進階學習之屏幕適配:http://blog.csdn.net/itcastcpp/article/details/18608437 背景 在學習cocos2dx時,我們在main函數中發現一句代碼, [cpp] view plaincopyprint #includemain.h #includeAppDelegate.h #includeCCEGLVie

        http://blog.csdn.net/itcastcpp/article/details/18608437 背景 在學習cocos2dx時,我們在main函數中發現一句代碼, [cpp] view plaincopyprint? #includemain.h #includeAppDelegate.h #includeCCEGLView.h USING_NS_CC; int APIENTRY_tWinMain( HINSTANCE

        http://blog.csdn.net/itcastcpp/article/details/18608437

        背景

        在學習cocos2dx時,我們在main函數中發現一句代碼,

        [cpp] view plaincopyprint?

        1. #include "main.h"
        2. #include "AppDelegate.h"
        3. #include "CCEGLView.h"
        4. USING_NS_CC;
        5. int APIENTRY _tWinMain(HINSTANCE hInstance,
        6. HINSTANCE hPrevInstance,
        7. LPTSTR lpCmdLine,
        8. int nCmdShow)
        9. {
        10. UNREFERENCED_PARAMETER(hPrevInstance);
        11. UNREFERENCED_PARAMETER(lpCmdLine);
        12. // create the application instance
        13. AppDelegate app;
        14. CCEGLView* eglView = CCEGLView::sharedOpenGLView();
        15. eglView->setViewName("CrazyMario");
        16. eglView->setFrameSize(480, 320);
        17. return CCApplication::sharedApplication()->run();
        18. }

        #include "main.h"
        #include "AppDelegate.h"
        #include "CCEGLView.h"
        
        USING_NS_CC;
        
        int APIENTRY _tWinMain(HINSTANCE hInstance,
         HINSTANCE hPrevInstance,
         LPTSTR lpCmdLine,
         int nCmdShow)
        {
         UNREFERENCED_PARAMETER(hPrevInstance);
         UNREFERENCED_PARAMETER(lpCmdLine);
        
         // create the application instance
         AppDelegate app;
         CCEGLView* eglView = CCEGLView::sharedOpenGLView();
         eglView->setViewName("CrazyMario");
         eglView->setFrameSize(480, 320);
         return CCApplication::sharedApplication()->run();
        }

        那就是eglView->setFrameSize(480,320),這句代碼設置了窗口的大小,一般說來手機游戲需要全屏顯示,所以對于不同分辨率的手機,setFrameSize要求不一樣的。這樣是不是很崩潰?因為我們代碼里很多地方可能也要改,圖片大小可能也要改,那怎么辦呢?

        其實cocos2dx已經為我們做好了這一切

        結局方案

        這個方案就是調用eglView->setDesignResolutionSize(480, 320, kResolutionShowAll);來告訴cocos2dx,我的程序是按照480,320來設計的,那么setFrameSize如果不是480,320那么cocos2dx會按照比例給我們做適配,不用我們做別的事情。

        在超級馬里奧這個游戲里,在AppDelegate中已經調用了setDesignResolutionSize函數設置設計大小為480,320

        那么在setFrameSize不同的情況下,也不會引起圖片比例不合適的情況,只是窗口大小會發生變化而已


        在480*320的情況下


        在960*640的情況下,只是界面變大了,圖片沒有任何的不適合


        setDesignResolutionSize的參數

        第三個參數的取值范圍如下:

        [cpp] view plaincopyprint?

        1. enum ResolutionPolicy
        2. {
        3. // The entire application is visible in the specified area without trying to preserve the original aspect ratio.
        4. // Distortion can occur, and the application may appear stretched or compressed.
        5. kResolutionExactFit,
        6. // The entire application fills the specified area, without distortion but possibly with some cropping,
        7. // while maintaining the original aspect ratio of the application.
        8. kResolutionNoBorder,
        9. // The entire application is visible in the specified area without distortion while maintaining the original
        10. // aspect ratio of the application. Borders can appear on two sides of the application.
        11. kResolutionShowAll,
        12. // The application takes the height of the design resolution size and modifies the width of the internal
        13. // canvas so that it fits the aspect ratio of the device
        14. // no distortion will occur however you must make sure your application works on different
        15. // aspect ratios
        16. kResolutionFixedHeight,
        17. // The application takes the width of the design resolution size and modifies the height of the internal
        18. // canvas so that it fits the aspect ratio of the device
        19. // no distortion will occur however you must make sure your application works on different
        20. // aspect ratios
        21. kResolutionFixedWidth,
        22. kResolutionUnKnown,
        23. };

        enum ResolutionPolicy
        {
         // The entire application is visible in the specified area without trying to preserve the original aspect ratio.
         // Distortion can occur, and the application may appear stretched or compressed.
         kResolutionExactFit,
         // The entire application fills the specified area, without distortion but possibly with some cropping,
         // while maintaining the original aspect ratio of the application.
         kResolutionNoBorder,
         // The entire application is visible in the specified area without distortion while maintaining the original
         // aspect ratio of the application. Borders can appear on two sides of the application.
         kResolutionShowAll,
         // The application takes the height of the design resolution size and modifies the width of the internal
         // canvas so that it fits the aspect ratio of the device
         // no distortion will occur however you must make sure your application works on different
         // aspect ratios
         kResolutionFixedHeight,
         // The application takes the width of the design resolution size and modifies the height of the internal
         // canvas so that it fits the aspect ratio of the device
         // no distortion will occur however you must make sure your application works on different
         // aspect ratios
         kResolutionFixedWidth,
        
         kResolutionUnKnown,
        };

        kResolutionExactFit:會靠拉伸來填滿屏幕,本例來說背景圖會變形來填充屏幕,因為1024:768=1.3, 480:320=1.5,寬高比不同,圖片也就無法等比縮放來填滿屏幕,只能變形了。
        kResolutionNoBorder: 看不到黑邊,實際就是寬高等比縮放,但縮放比例取寬比和高比之中大的那一個。
        kResolutionShowAll:全部顯示,可以理解為保證內容都顯示在屏幕之內,實際也是寬高等比縮放,但縮放比例取寬比和高比之中小的那一個。

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        cocos2dx進階學習之屏幕適配

        cocos2dx進階學習之屏幕適配:http://blog.csdn.net/itcastcpp/article/details/18608437 背景 在學習cocos2dx時,我們在main函數中發現一句代碼, [cpp] view plaincopyprint #includemain.h #includeAppDelegate.h #includeCCEGLVie
        推薦度:
        標簽: 屏幕 學習 blog
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 免费的黄网站男人的天堂| 成人性生交大片免费看好| 国产亚洲男人的天堂在线观看 | 一级黄色毛片免费看| 91禁漫免费进入| 国产三级免费电影| 亚洲视频在线观看网站| 黄页网站在线视频免费| 在线观看www日本免费网站| 国产亚洲美女精品久久久| 亚洲精品人成网线在线播放va| 免费av片在线观看网站| 亚洲av午夜成人片精品电影 | 亚洲AV人无码激艳猛片| 视频一区在线免费观看| 亚洲国产aⅴ综合网| 好男人资源在线WWW免费| 又粗又大又硬又爽的免费视频| 亚洲国产成人资源在线软件| 国产免费区在线观看十分钟 | 日韩视频在线免费观看| 亚洲电影在线播放| 免费黄网站在线看| 亚洲成人免费在线观看| 91免费国产精品| 亚洲中文字幕久久久一区| 免费AA片少妇人AA片直播| 91天堂素人精品系列全集亚洲| 成人免费视频77777| 亚洲最大成人网色香蕉| 成人免费福利视频| 亚洲成人网在线播放| 国产又大又粗又硬又长免费| 国产一级高青免费| 国产成人精品亚洲日本在线| 亚洲第一页日韩专区| 日韩精品无码一区二区三区免费| 久久久久亚洲精品男人的天堂| 久久免费国产视频| 中文字幕亚洲综合久久2| 国产三级免费观看|