cocos2d-x适配多分辨率
来源:互联网 发布:淘宝春装什么时候上新 编辑:程序博客网 时间:2024/05/15 00:38
applicationDidFinishLaunching()函数中根据屏幕分辨率来设置
static Resource iPhoneResource = {CCSizeMake(480,320), "iPhone" };
static Resource iPhoneHDResource = {CCSizeMake(480*2,320*2), "iPhoneHD" };
static Resource iPhoneTallerResource = {CCSizeMake(1136,640), "iPhoneTaller"};
static Resource iPadResource = {CCSizeMake(1024,768), "iPad" };
static Resource iPadHDResource = {CCSizeMake(2048,1536),"iPadHD" };
static CCSize designResolutionSize =CCSizeMake(480,320);
static CCSize designTallerResolutionSize =CCSizeMake(568,320);
static CCSize designIpadResolutionSize =CCSizeMake(512,384);
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)
{
//iPhoneHDResource.directory是共用路径,这个路径下有共用资源。
searchPath.push_back(iPadHDResource.directory);
searchPath.push_back(iPhoneHDResource.directory);
//设计屏幕大小是512x384
designSize = designIpadResolutionSize;
pEGLView->setDesignResolutionSize(designSize.width, designSize.height,kResolutionNoBorder);
//实际屏幕大小是2048x1536,所以设置ContentScaleFactor为4.
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);
}
- cocos2d-x适配多分辨率
- cocos2d-x适配多分辨率
- cocos2d-x分辨率自适应
- cocos2d-x多分辨率
- Cocos2d-x 多分辨率支持
- cocos2d-x 多分辨率支持
- cocos2d-x 多分辨率支持
- cocos2d-x 多分辨率设定
- Cocos2d-x 多分辨率支持
- Cocos2d-x 多分辨率支持
- Cocos2d-x 分辨率自适应解决方案
- cocos2d-x 适应不同分辨率 .
- [Cocos2D-X官方文档]:Cocos2d-x分辨率的适配
- Cocos2d-x的多分辨率解决方案
- Cocos2d-x 2.0 自适应多种分辨率
- Cocos2d-x的多分辨率解决方案
- Cocos2d-x 2.0 自适应多种分辨率
- cocos2d-x android多分辨率适配
- Yii加载CSS文件或者JS文件
- 转--Myeclipse8.5 反编译插件 jad 安装
- 驱动调试常见问题_Camera
- GridView修改含有DropDownList控件列的宽度
- 验证任意一个大于4并且小于500的偶数都可以拆分成两个素数之和
- cocos2d-x适配多分辨率
- 深度解析:清理烂代码
- Git下的冲突解决
- hadoop-1.1.2 在Windows环境下的部署
- poj 2318 TOYS
- Canvas教程 Canvas tutorial
- iOS JSON数据封装与解析
- Camera 图像处理原理分析- 亮度及曝光控制
- ZooKeeper和Diamond的异同