cocos2d-x自適應屏幕

上午解決屏幕自適應性的問題,找到一個簡便的方法。記錄下網絡

在AppDelegate.cpp中加幾句代碼app

 1 bool AppDelegate::applicationDidFinishLaunching()
 2 {
 3     // initialize director
 4     CCDirector *pDirector = CCDirector::sharedDirector();
 5     //自適應屏幕
 6     CCEGLView *pEGLView = CCEGLView::sharedOpenGLView();
 7     pDirector->setOpenGLView(pEGLView);
 8     pEGLView->setDesignResolutionSize(320,480,kResolutionShowAll);
 9 
10     // turn on display FPS
11     pDirector->setDisplayStats(true);
12 
13     // set FPS. the default value is 1.0/60 if you don't call this
14     pDirector->setAnimationInterval(1.0 / 60);
15 
16     // create a scene. it's an autorelease object
17    CCScene *pScene = HelloWorld::scene();
18 
19     //CCScene *pScene = CCGameScene::scene();
20 
21     // run
22     pDirector->runWithScene(pScene);
23     return true;
24 }

其實2.0給咱們提供了三適配策略this

kResolutionNoBorder:超出屏幕的部分會被裁剪,兩側沒有黑邊,鋪滿屏幕,按圖片原始比例顯示,圖片不變形。
kResolutionShowAll:整個遊戲界面是可見的,會按原始比例進行縮放,圖片不變形,但兩側可能會留有黑邊,不鋪滿屏幕。
kResolutionExactFit:整個遊戲界面是可見的,圖片可能會進行拉伸或者壓縮處理,鋪滿屏幕,圖片會變形。
spa

 

查了下,網絡上有不少牛人給出瞭解決方案。也能夠根據相對位置進行適配code

相關文章
相關標籤/搜索