cocos2d-x自适应屏幕

上午解决屏幕自适应性的问题,找到一个简便的方法。记录下

在AppDelegate.cpp中加几句代码

 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给我们提供了三适配策略

kResolutionNoBorder:超出屏幕的部分会被裁剪,两侧没有黑边,铺满屏幕,按图片原始比例显示,图片不变形。
kResolutionShowAll:整个游戏界面是可见的,会按原始比例进行缩放,图片不变形,但两侧可能会留有黑边,不铺满屏幕。
kResolutionExactFit:整个游戏界面是可见的,图片可能会进行拉伸或者压缩处理,铺满屏幕,图片会变形。

查了下,网络上有很多牛人给出了解决方案。也可以根据相对位置进行适配

原文地址:https://www.cnblogs.com/sambird/p/3197660.html