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行业也不是站在风口上,猪也能吹上天的世道了.作为技术小菜的我,再找工作那几个月真是战 ...
随机推荐
- js中substring或split方法取得URL中的域名
1.split方式 <html> <head></head> <body onload="convertTemp()"> <s ...
- 设计模式(4)-对象创建型模式-Prototype模式
1.对象创建型模式 1.4 Protoype模式 1.4.1需求 通过拷贝原形对象创建新的对象. 1.4.2结构 •P r o t o t y p e(Gr a p h i c) - ...
- hdu 1070Milk
地址链接:http://acm.hdu.edu.cn/showproblem.php?pid=1070 题意:多看几遍,学着静下来心去看英文题 代码: #include<bits/stdc++. ...
- opencv 训练自己的分类器汇总
原地址:http://www.cnblogs.com/zengqs/archive/2009/02/12/1389208.html OpenCV训练分类器 OpenCV训练分类器 一.简介 目标检测方 ...
- Visual Studio Installer打包后生成的安装文件每次执行都需要重新安装C++ 2010运行库(x86)的解决方案
原文:Visual Studio Installer打包后生成的安装文件每次执行都需要重新安装C++ 2010运行库(x86)的解决方案 如果你是用Visual Studio自带的打包项目打包了一个I ...
- 创建并使用静态库(ar 命令)
创建并使用静态库(ar 命令) archive命令的功能是:创建或改动归档文件或者从归档文件里析取信息.能够简单的理解为一个打包工具,将成员文件依照一定的规则构建到.a文件里, ...
- 前后端分离Web项目中,RBAC实现的研究
在前后端分离Web项目中,RBAC实现的研究 最近手头公司的网站项目终于渐渐走出混沌,走上正轨,任务也轻松了一些,终于有时间整理和总结一下之前做的东西. 以往的项目一般使用模板引擎(如ejs)渲染 ...
- MySQLdb 连接Mysql 数据库出错解决
#coding=utf-8 import MySQLdb if __name__ == "__main__": db = MySQLdb.connect(host=<sp ...
- codefroce D. Powerful array[初识块状数组]
codefroce D. Powerful array[初识块状数组] 由于是初始所以,仅仅能先用别人的分析.囧... 题目: 给定一个数列:A1, A2,--,An,定义Ks为区间(l,r)中s出现 ...
- ReferenceError: Error #1069: 在 spark.components.RadioButtonGroup 上找不到属性 label,且没有默认值
1.错误描写叙述 ReferenceError: Error #1069: 在 spark.components.RadioButtonGroup 上找不到属性 label,且没有默认值. at Ch ...