<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
        主站蜘蛛池模板: 中文字幕无码精品亚洲资源网久久| aa午夜免费剧场| 69精品免费视频| 成年女人午夜毛片免费视频| 在线观看无码的免费网站| 国内精品久久久久久久亚洲| 亚洲成av人片在线看片| 最近免费中文字幕大全免费| 久久久久亚洲AV成人片| 亚洲AV日韩综合一区| 色www永久免费视频| 亚洲国产精品成人午夜在线观看| 久久九九久精品国产免费直播| 在线a亚洲v天堂网2018| 四虎成人精品国产永久免费无码| jlzzjlzz亚洲乱熟在线播放| 三年片免费高清版| 亚洲精选在线观看| 午夜国产精品免费观看| 亚洲欧好州第一的日产suv| 免费毛片在线播放| 一级免费黄色毛片| 高清国语自产拍免费视频国产| 亚洲av日韩精品久久久久久a| 亚洲高清最新av网站| a色毛片免费视频| 日韩a在线观看免费观看| 粉色视频在线观看www免费| 久久精品国产精品亚洲| 一级毛片**不卡免费播| 亚洲午夜一区二区三区| 免费一级毛片在线播放不收费 | 国产在线a不卡免费视频| 国产成人亚洲精品播放器下载| 亚洲综合国产精品第一页| 日本一卡精品视频免费| 国产成人麻豆亚洲综合无码精品| 久章草在线精品视频免费观看| 亚洲线精品一区二区三区| 日韩在线视频线视频免费网站| 亚洲国产精品久久久久网站|