现在用的2d-x版本是2.1.1。现在的项目要求是iphone ,iphone Retina,ipad和ipad Retina都有各自的路径来存放各自需要的资源。在AppDelegate的

applicationDidFinishLaunching()函数中根据屏幕分辨率来设置

, ),   "iPhone" };

*, *),   "iPhoneHD" };

, ),    "iPhoneTaller"};

, ),  "iPad"   };

, ), "iPadHD" };

, );

, );

, );

bool AppDelegate::applicationDidFinishLaunching()

{

// initialize director

CCDirector *pDirector = CCDirector::sharedDirector();

CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

pDirector->setOpenGLView(pEGLView);

std::vector<std::string> searchPath = CCFileUtils::sharedFileUtils()->getSearchPaths();

// Set the design resolution

pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder);

CCSize designSize = designResolutionSize;

CCSize frameSize = pEGLView->getFrameSize();

_isLongiPhone = false;

_isIpadHD = false;

_isIpadNormal = false;

// In this demo, we select resource according to the frame's height.

// If the resource size is different from design resolution size, you need to set contentScaleFactor.

// We use the ratio of resource's height to the height of design resolution,

// this can make sure that the resource's height could fit for the height of design resolution.

// if the frame's height is larger than the height of medium resource size, select large resource.

if (frameSize.height == iPadHDResource.size.height && frameSize.width == iPadHDResource.size.width)

{

searchPath.push_back(iPadHDResource.directory);

searchPath.push_back(iPhoneHDResource.directory);

designSize = designIpadResolutionSize;

pEGLView->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);

pDirector->setContentScaleFactor(iPadHDResource.size.height/designIpadResolutionSize.height);

_isIpadHD = true;

}

// if the frame's height is larger than the height of small resource size, select medium resource.

elseif (frameSize.height == iPadResource.size.height && frameSize.width == iPadResource.size.width)

{

searchPath.push_back(iPadResource.directory);

searchPath.push_back(iPhoneHDResource.directory);

designSize = designIpadResolutionSize;

pEGLView->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);

pDirector->setContentScaleFactor(iPadResource.size.height/designIpadResolutionSize.height);

_isIpadNormal = true;

}

// if the frame's height is smaller than the height of medium resource size, select small resource.

elseif (frameSize.height == iPhoneResource.size.height && frameSize.width == iPhoneResource.size.width)

{

searchPath.push_back(iPhoneResource.directory);

searchPath.push_back(iPhoneHDResource.directory);

pDirector->setContentScaleFactor(iPhoneResource.size.height/designResolutionSize.height);

}

elseif (frameSize.height == iPhoneHDResource.size.height && frameSize.width == iPhoneHDResource.size.width){

searchPath.push_back(iPhoneHDResource.directory);

pDirector->setContentScaleFactor(iPhoneHDResource.size.height/designResolutionSize.height);

designSize = designResolutionSize;

pEGLView->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);

}

elseif (frameSize.height == iPhoneTallerResource.size.height && frameSize.width == iPhoneTallerResource.size.width){

//push taller resources" directory first,so look for resources in  taller resources" directory first

searchPath.push_back(iPhoneTallerResource.directory);

searchPath.push_back(iPhoneHDResource.directory);

designSize = designTallerResolutionSize;

pEGLView->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);

pDirector->setContentScaleFactor(iPhoneTallerResource.size.height/designResolutionSize.height);

_isLongiPhone = true;

}

CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath);

}


这样设置路径之后,进入游戏时会在
SearchPaths里寻找所需要的资源。需要注意的是各个路径下的资源文件相同就行了,不用根据是否未Retina而添加-HD后缀。

cocos2d-x适配多分辨率的更多相关文章

  1. Unity2D多分辨率屏幕适配方案(转载)

    一下内容转自:http://imgtec.eetrend.com/forum/3992 此文将阐述一种简单有效的Unity2D多分辨率屏幕适配方案,该方案适用于基于原生开发的Unity2D游戏,即没有 ...

  2. [原创]一种Unity2D多分辨率屏幕适配方案

    此文将阐述一种简单有效的Unity2D多分辨率屏幕适配方案,该方案适用于基于原生开发的Unity2D游戏,即没有使用第三方2D插件,如Uni2D,2D toolkit等开发的游戏,NGUI插件不受这个 ...

  3. 一种Unity2D多分辨率屏幕适配方案

    http://www.cnblogs.com/flyFreeZn/p/4073655.html 此文将阐述一种简单有效的Unity2D多分辨率屏幕适配方案,该方案适用于基于原生开发的Unity2D游戏 ...

  4. Unity 手机屏幕适配

    ////如有侵权 请联系我进行删除 email:YZFHKM@163.com 1.游戏屏幕适配 屏幕适配是为了让我们的项目能够跑在各种电子设备上(手机,平板,电脑) 那么了解是适配之前首先要了解两个知 ...

  5. dp和px转换

    在编写自定义view的时候,通常会在onTouchEvent回调方法中进行一些关乎距离的判断逻辑,这里的距离常量如果适配到多分辨率的不同设备上时可能会出现一些错乱的问题. 所以一般来说,常常需要dp到 ...

  6. Python爬取CSDN博客文章

    0 url :http://blog.csdn.net/youyou1543724847/article/details/52818339Redis一点基础的东西目录 1.基础底层数据结构 2.win ...

  7. Unity GUI选择与评价

    因为Unity内建的GUI不管是不是从开发效率或效率强制,因此,许多派生GUI插入,什么插件的选择,是一个非常值它被认为是. 既然是评价,就会有非常多的主观意识,这不一定成为选择的根据. 再比方.我已 ...

  8. 中国移动能力开放商店OneNET View数据可视化公测 10分钟轻便生成行业可视化界面

    随着云计算,5G技术,人工智能等底层技术的发展,万物互联时代已经到来,同时带来了海量数据,如何效果好.低成本.短时间的表现据,成为物联网行业从业者和公司的当务之急. OneNET View传统的数据展 ...

  9. 资本寒冬下的android面经

    在2018年10月初,公司倒闭,无奈走上找工作的道路,不想自己平时图安逸,不思进取,再次找工作才发现,android行业也不是站在风口上,猪也能吹上天的世道了.作为技术小菜的我,再找工作那几个月真是战 ...

随机推荐

  1. spice for openstack

    nova.conf vnc_enabled=False [Spice] agent_enabled=True enabled=True html5proxy_base_url=http://x.x.x ...

  2. cocos2d-x中使用JNI的调用JAVA方法

    用cocos2d-x公布Android项目时.都应该知道要用JAVA与C/C++进行交互时会涉及到JNI的操作(Java Native Interface).JNI是JAVA的一个通用接口.旨在本地化 ...

  3. 在安装mysql出现的错误以及解决方法

    因为手贱更新了一下驱动,结果导致无线网卡出了问题.然而就算是从官网上下载了驱动各种折腾也没有弄好,心里特别堵.无奈只有重装系统这一条路了.这里表示特别难过,因为电脑上东西实在太多了,而且各种环境变量. ...

  4. Gulp.js简介

    Gulp.js简介 我们讨论了很多关于怎么减少页面体积,提高重网站性能的方法.有些是操作是一劳永逸的,如开启服务器的gzip压缩,使用适当的图片格式,或删除一些不必要的字符.但有一些任务是每次工作都必 ...

  5. osc搜索引擎框架search-framework,TngouDB,gso,

    项目目的:OSChina 实现全文搜索的简单封装框架 License: Public Domain 包含内容: 重建索引工具 -> IndexRebuilder.java 增量构建索引工具 -& ...

  6. 用jsp写注冊页面

    包含单选框.多选框.session的应用,页面自己主动跳转,中文乱码的处理,入门级 对于中文乱码的处理,注意几点:注冊页面数据提交方式为post不能忘了写,页面编码方式为gbk,处理提交信息的doRe ...

  7. 如何搭建DNS服务(转)

    继NTP时间服务器后,继续搭建DNS服务,鉴于昨晚撰写时间超过预期,这次改变策略,先把自己需要用到的部分写出来(主要是基于RAC的搭建,只涉及正向和反向DNS解析),后面再添加必要的说明和阐述. 试验 ...

  8. CSS实现输入框的高亮效果-------Day50

    又到周末了,这一天天过的真快,明天应该回老家了.不知道会不会有机会进行编写.尽量争取吧,实在不想就这样间断.假设说从前会一天天无聊到爆,那如今自己应该是一天天忙的要死,欠缺了太多东西,那些浪费的时间可 ...

  9. 采用CXF+spring+restful创建一个web接口项目

    这篇文章是http://blog.csdn.net/zxnlmj/article/details/28880303下面,加入的基础上的restful特征 1.参加restful必jar包裹 jsr31 ...

  10. Hadoop云计算大数据书籍分享

    1. 推荐书名    大数据云计算利器: Hadoop, The Definitive Guide, 1Ed.pdf(第1版)    大数据云计算利器: Hadoop, The Definitive ...