分辨率自适应!一句话搞定IOS android windows!!

前几天我用在windows下面写好的程序..忽然需求要移植成安卓和ios平台.于是遇到了各种麻烦..最棘手的一个就是分辨率的自适应,我工程的图片用的都是800x480的..

可是iphone上面的分辨率是480x320...这可头疼了..

于是我找了很多资料后.发现有一个很简单的方法.但是需要:



需要新版本的cocos2d-x  我是直接从2.0.1升级到2.0.3版本..(请用cocos2d-x2.0.3版本)

AppDelegate.cpp

  1. bool AppDelegate::applicationDidFinishLaunching()  
  2. {  
  3.     // initialize director   
  4.     CCDirector *pDirector = CCDirector::sharedDirector();  
  5.     pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());  
  6.   
  7.     // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.   
  8. //     pDirector->enableRetinaDisplay(true);   
  9.     CCEGLView::sharedOpenGLView()->setDesignResolutionSize(800, 480,kResolutionShowAll);  
  10.   
  11.     // turn on display FPS   
  12.     pDirector->setDisplayStats(false);  
  13.   
  14.     // set FPS. the default value is 1.0/60 if you don't call this   
  15.     pDirector->setAnimationInterval(1.0 / 60);  
  16.   
  17.     // create a scene. it's an autorelease object   
  18.     CCScene *pScene = HelloWorld::scene();  
  19.   
  20.     // run   
  21.     pDirector->runWithScene(pScene);  
  22.     return true;  
  23. }  
上面的代码中..有下面一句是被注释掉的..老版本的cocos2d-x也有这句.但是新版本的多了一个参数.多的那个参数是什么意思呢?
  1. CCEGLView::sharedOpenGLView()->setDesignResolutionSize(800, 480,kResolutionShowAll);  


是一个枚举..注释说明了一切..大概意思就是.
选择kResolutionExactFit则会拉伸至充满整个屏幕
选择kResolutionShowAll则不会拉伸,但是会留上下等宽的黑边.

  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.       
  13.     kResolutionUnKnown,  
  14. };  
有人一定会想,,那这样的话..那些判断矩形,触碰之类的会不会偏离?答案是不会.等比缩放包括所有的组件..所有大家放心的使用..


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值