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行业也不是站在风口上,猪也能吹上天的世道了.作为技术小菜的我,再找工作那几个月真是战 ...
随机推荐
- (2)入门指南——(7)添加jquery代码(Adding our jQuery code)
Our custom code will go in the second, currently empty, JavaScript file which we included from the H ...
- Github干货系列:C++资源集合-
Awesome CPP,这又是一个 Awesome XXX 系列的资源整理,由 fffaraz 发起和维护.内容包括:标准库.Web应用框架.人工智能.数据库.图片处理.机器学习.日志.代码分析等. ...
- Go的String转码包
https://github.com/qiniu/iconv https://github.com/djimenez/iconv-go 这是与go不相干的转码包:https://github.com/ ...
- listview改变选中行字体颜色
[android]listview改变选中行字体颜色 目标:选中item,其字体设置为#3197FF,未选中的,其字体为#FFFFFF 与listvew设置选中行item背景图片一样,使用select ...
- VSC调试.NET Core 应用程序
VS Code 从零开始开发并调试.NET Core 应用程序 使用VS Code 从零开始开发并调试.NET Core 应用程序,C#调试. 上一篇 使用VS Code开发 调试.NET Core ...
- Android架构设计和软硬整合完整训练
Android架构设计和软硬整合完整训练 Android架构设计和软硬整合完整训练:HAL&Framework&Native Service&Android Service&a ...
- 常见问题(FAQ) | VPNCUP
常见问题(FAQ) | VPNCUP 常见问题(FAQ) 关于FAQ 新手开始 登录验证问题 为什么刚注册后,登录VPN服务器提示错误? 免费注册的用户有哪些限制? 为什么连接免费VPN后20分钟自动 ...
- iptables 小结
最近工作上一个作业用到了iptables命令,主要进行端口映射,在网上查了好多资料,尽管有很多例子,但还是整了好几天才整明白.在这里将学习到的知识总结一下.以下均属个人见解.(有一些是从网络中总结的, ...
- c++重载ostream的实现
#include <iostream> using namespace std; class Point{ public: Point(int _x = 0, int _y = 0, in ...
- 折扣&折让-看清实质的思考
折扣&折让 看清实质的思考 Author:zfive5(zidong) Email:zfive5@163.com 引子 有些东西,在没有人指点的情况,一时理解不了,就放一放,等到某一个契机到来 ...