cocos2d-x适配多分辨率
现在用的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适配多分辨率的更多相关文章
- Unity2D多分辨率屏幕适配方案(转载)
一下内容转自:http://imgtec.eetrend.com/forum/3992 此文将阐述一种简单有效的Unity2D多分辨率屏幕适配方案,该方案适用于基于原生开发的Unity2D游戏,即没有 ...
- [原创]一种Unity2D多分辨率屏幕适配方案
此文将阐述一种简单有效的Unity2D多分辨率屏幕适配方案,该方案适用于基于原生开发的Unity2D游戏,即没有使用第三方2D插件,如Uni2D,2D toolkit等开发的游戏,NGUI插件不受这个 ...
- 一种Unity2D多分辨率屏幕适配方案
http://www.cnblogs.com/flyFreeZn/p/4073655.html 此文将阐述一种简单有效的Unity2D多分辨率屏幕适配方案,该方案适用于基于原生开发的Unity2D游戏 ...
- Unity 手机屏幕适配
////如有侵权 请联系我进行删除 email:YZFHKM@163.com 1.游戏屏幕适配 屏幕适配是为了让我们的项目能够跑在各种电子设备上(手机,平板,电脑) 那么了解是适配之前首先要了解两个知 ...
- dp和px转换
在编写自定义view的时候,通常会在onTouchEvent回调方法中进行一些关乎距离的判断逻辑,这里的距离常量如果适配到多分辨率的不同设备上时可能会出现一些错乱的问题. 所以一般来说,常常需要dp到 ...
- Python爬取CSDN博客文章
0 url :http://blog.csdn.net/youyou1543724847/article/details/52818339Redis一点基础的东西目录 1.基础底层数据结构 2.win ...
- Unity GUI选择与评价
因为Unity内建的GUI不管是不是从开发效率或效率强制,因此,许多派生GUI插入,什么插件的选择,是一个非常值它被认为是. 既然是评价,就会有非常多的主观意识,这不一定成为选择的根据. 再比方.我已 ...
- 中国移动能力开放商店OneNET View数据可视化公测 10分钟轻便生成行业可视化界面
随着云计算,5G技术,人工智能等底层技术的发展,万物互联时代已经到来,同时带来了海量数据,如何效果好.低成本.短时间的表现据,成为物联网行业从业者和公司的当务之急. OneNET View传统的数据展 ...
- 资本寒冬下的android面经
在2018年10月初,公司倒闭,无奈走上找工作的道路,不想自己平时图安逸,不思进取,再次找工作才发现,android行业也不是站在风口上,猪也能吹上天的世道了.作为技术小菜的我,再找工作那几个月真是战 ...
随机推荐
- 使用AjaxFileUpload.js实现文件异步上�
ajax是无法提交文件的,所以在上传图片并预览的时候,我们常常使用Ifame的方法实现看似异步的效果.可是这样总不是非常方便的,AjaxFilleUpload.js对上面的方法进行了一个包装,使得我们 ...
- 中国大概可用NTPserver地址
133.100.11.8 prefer210.72.145.44203.117.180.36131.107.1.10time.asia.apple.com64.236.96.53130.149.17. ...
- eclipse设置关联文件打开方式
window->preferences: General->Editors->File Associations
- php使用http请求头实现文件下载
众所周知php对http协议的依赖特别强,像java或者asp.net在某些情况下可以不依赖http例如asp.net的winform,对php来说文件下载可以使用http的请求头加上php的IO就可 ...
- copy算法
copy------强化效率无所不用其极 copy(first,last,result)算法可将输入区间[first,last)内的元素拷贝到输出区间[result,result+(last-f ...
- facebook打开动画pop
POP源代码:https://github.com/facebook/pop demo相关链接:https://github.com/jxd001/POPdemo/blob/master/README ...
- Git中的merge命令实现和工作方式
想象一下有例如以下情形:代码库中存在两个分支,而且每一个分支都进行了改动.最后你想要将当中的一个分支合并到其它的分支中.个人博客网址 http://swinghu.github.com/ 那么要问合并 ...
- HDU2602 Bone Collector 【01背包】
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- CodeForces 484B Maximum Value
意甲冠军: a序列n(2*10^5)数字 问道a[i]>=a[j]如果是 a[i]%a[j]最大值是多少 思路: 感觉是一道挺乱来的题-- 我们能够将ans表示为a[i]-k*a[j] 这 ...
- HDU 2255 奔小康,赚钱(KM算法模板)
解决问题的思路: 二部图,正确的匹配,卡费用流,使用KM算法. #include <cstring> #include <algorithm> #include <cst ...