【Cocos2d-x】新手自学(十)分辨率自适应!一句话搞定IOS android windows!!
来源:互联网 发布:淘宝店买卖平台 编辑:程序博客网 时间:2024/05/20 04:30
前几天我用在windows下面写好的程序..忽然需求要移植成安卓和ios平台.于是遇到了各种麻烦..最棘手的一个就是分辨率的自适应,我工程的图片用的都是800x480的..
可是iphone上面的分辨率是480x320...这可头疼了..
于是我找了很多资料后.发现有一个很简单的方法.但是需要:
需要新版本的cocos2d-x 我是直接从2.0.1升级到2.0.3版本..(请用cocos2d-x2.0.3版本)
AppDelegate.cpp
bool AppDelegate::applicationDidFinishLaunching(){ // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.// pDirector->enableRetinaDisplay(true);CCEGLView::sharedOpenGLView()->setDesignResolutionSize(800, 480,kResolutionShowAll); // turn on display FPS pDirector->setDisplayStats(false); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object CCScene *pScene = HelloWorld::scene(); // run pDirector->runWithScene(pScene); return true;}
上面的代码中..有下面一句是被注释掉的..老版本的cocos2d-x也有这句.但是新版本的多了一个参数.多的那个参数是什么意思呢?
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(800, 480,kResolutionShowAll);
是一个枚举..注释说明了一切..大概意思就是.
选择kResolutionExactFit则会拉伸至充满整个屏幕
选择kResolutionShowAll则不会拉伸,但是会留上下等宽的黑边.
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, kResolutionUnKnown,};
有人一定会想,,那这样的话..那些判断矩形,触碰之类的会不会偏离?答案是不会.等比缩放包括所有的组件..所有大家放心的使用..
- 【Cocos2d-x】新手自学(十)分辨率自适应!一句话搞定IOS android windows!!
- 分辨率自适应!一句话搞定IOS android windows!!
- cocos2d-x分辨率自适应
- Cocos2d-x 分辨率自适应解决方案
- cocos2d-x-2.1项目android自适应不同分辨率
- cocos2d-x自适应android不同分辨率,使用多套资源
- cocos2d-x自适应android不同分辨率,使用多套资源
- Cocos2d-x 2.0 自适应多种分辨率
- Cocos2d-x 2.0 自适应多种分辨率
- Cocos2d-x 2.0 自适应多种分辨率
- cocos2d-x 3.0 分辨率自适应方案
- cocos2d-x 3.0 分辨率自适应方案
- Cocos2d-x 2.0 自适应多种分辨率
- Cocos2d-x 2.0 自适应多种分辨率
- 【Cocos2d-x】新手自学(六)文字菜单
- 【新手自学Cocos2d-x】2.打开Cocos2d-x工程示例。
- 最新 cocos2d-x自适应android不同分辨率,使用多套资源
- Cocos2d-x笔记(五)自适应多种分辨率
- 学习组织开会
- java动态代理(JDK和cglib)
- 操作系统理论的探索: (之四)
- Windows核心编程学习笔记(3)--获得可执行文件的实例和dll文件的实例句柄
- Android TextView 添加链接
- 【Cocos2d-x】新手自学(十)分辨率自适应!一句话搞定IOS android windows!!
- ubuntu下编译vlc-android(0.0.5版本)
- zoj 1392.The Hardest Problem Ever
- levenshtein_distance(字符串相似度算法)
- 31.黑马程序员-多线程(继承Thread)
- 项目管理者对管理的总结
- C语言如何获得精确到毫秒的时间
- 强制转换带来的疑惑
- const 和 define