cocos2d-x 手机屏幕多分辨率适应的问题。

cocos2d-x在开发游戏时 常常会遇到手机屏幕分辨率不统一,导致加载到不同分辨率下显示出游戏效果出现不一致的问题。

在cocos2d-x 2.0版本以后可以使用

virtual void setDesignResolutionSize(float width, float height, ResolutionPolicy resolutionPolicy);

解决

具体方法为:

1.首先确定一个你开发环境和图片资源所在的分辨率。也就是你在开发时,在确定的该分辨率下场景布局是正确的。(此处以iphone4s手机分辨率960*640为例)

2.在开发完成后在 AppDelegate.cpp 中

bool AppDelegate::applicationDidFinishLaunching();

接口当中

pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());

这行代码下面添加上这一句:

CCEGLView::sharedOpenGLView()->setDesignResolutionSize(960, 640, kResolutionExactFit);

如图:



此时在不同分辨率下 场景布局和排版会适应屏幕大小  不过 kResolutionExactFit 参数采取的是根据屏幕分辨率相对于960*640的图片或者控件的拉伸适应 也就是说如果分辨率过大,相关图片和精灵也会相应的变大,有可能会出现图片模糊。


该参数还可以传入其他几种模式:

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,

};


具体可以大家自己实验验证。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值