我正在使用cocos2d-x将我的cocos2d iPhone游戏移植到android。我现在面临屏幕分辨率问题:我想在我的游戏中使用一个高分辨率图像,所有屏幕都应该比给定分辨率低。
我在论坛上阅读了多个决议的this nice tutorial。这真的很有帮助,但我没有实现我的解决方案。设计分辨率和资源的资源比例因子有解释。资源解决方案。
但是,在我的情况下,它可以根据高度或宽度进行缩放。不是我的形象的完美缩放。有人可以为我澄清为什么吗?
答案 0 :(得分:3)
在AppDeligate.cpp中,将以下行添加到
设置glview后,bool AppDelegate :: applicationDidFinishLaunching()。
CCEGLView *ev = CCEGLView::sharedOpenGLView();
ev->setDesignResolutionSize(480, 320, kResolutionShowAll);
480,320是您为应用设计的分辨率。如果你想要肖像使用320,480代替。 如果手机宽高比与480/320宽高比不匹配,此解决方案将显示黑色边框。
答案 1 :(得分:1)
在AppDelegate.cpp
中这适用于横向模式
bool AppDelegate::applicationDidFinishLaunching()
{
// initialize director
director = CCDirector::sharedDirector();
EGLView = CCEGLView::sharedOpenGLView();
director->setOpenGLView(EGLView);
CCSize screenSize = EGLView->getFrameSize();
CCSize designSize = CCSizeMake(800, 480);
EGLView->setDesignResolutionSize(designSize.width,designSize.height, kResolutionExactFit);
if(screenSize.height > 480 && screenSize.height < 720 )
{
CCSize resourceSize = CCSizeMake(960, 540);
director->setContentScaleFactor(resourceSize.height/screenSize.height);
CCLog("Resolution Scale OF Karboon=%f",resourceSize.width/screenSize.width);
}
else if (screenSize.height >= 720 && screenSize.height < 800)
{
CCSize resourceSize = CCSizeMake(1280, 720);
director->setContentScaleFactor(resourceSize.height/screenSize.height);
CCLog("Resolution Scale OF NOTE=%f",resourceSize.width/screenSize.width);
}
else if(screenSize.height > 800)
{
CCSize resourceSize = CCSizeMake(1920, 1080);
director->setContentScaleFactor(resourceSize.height/screenSize.height);
CCLog("Resolution Scale OF Nexus=%f",resourceSize.width/screenSize.width);
}
else
{
director->setContentScaleFactor(1);
CCLog("Resolution Scale OF S Advance=%f");
}
return true;
}
答案 2 :(得分:0)
以下是一些可能有助于您在“资源”文件夹中创建以下文件夹的代码
ipadhd iPad的 iphone
在applicationdidfinishing方法
中的Appdelegate.cpp中使用此代码 CCSize screenSize = pEGLView->getFrameSize();
//set design size for iPad retina
CCSize designSize = CCSize(2048, 1536);
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionExactFit);
if (screenSize.height > 768) {
CCFileUtils::sharedFileUtils()->setResourceDirectory("ipadhd");
} else if (screenSize.height > 320) {
CCFileUtils::sharedFileUtils()->setResourceDirectory("ipad");
} else {
CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone");
}
pDirector->setContentScaleFactor(screenSize.height/designSize.height)
希望这会有所帮助。相应地将你的图像放在iphone文件夹中的iphone,ipad文件夹中的ipad图像和ipadhd文件夹中的高清图像中。 pDirector这里是CCDirector变量。
答案 3 :(得分:0)
我遵循了这个很好的教程http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Multi_resolution_support
这种方式对我有用。我使用了一个高分辨率图像
AppDelegate.cpp
typedef struct tagResource
{
cocos2d::CCSize size;
char directory[100];
}Resource;
static Resource smallResource = { cocos2d::CCSizeMake(320,480), "iphone" };
static Resource mediumResource = { cocos2d::CCSizeMake(768,1024), "ipad" };
static Resource largeResource = { cocos2d::CCSizeMake(1536,2048), "ipadhd" };
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(640,1024);
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
CCSize frameSize = pDirector->getOpenGLView()->getFrameSize();
pEGLView->setDesignResolutionSize( designResolutionSize.width, designResolutionSize.height, kResolutionExactFit);
if ((frameSize.height > mediumResource.size.height))
{
pDirector->setContentScaleFactor(largeResource.size.height/designResolutionSize.height);
}
// if the frame's height is larger than the height of small resource size, select medium resource.
else if ((frameSize.height > smallResource.size.height))
{
pDirector->setContentScaleFactor(mediumResource.size.height/designResolutionSize.height);
}
// if the frame's height is smaller than the height of medium resource size, select small resource.
else
{
pDirector->setContentScaleFactor(smallResource.size.height/designResolutionSize.height);
}
CCDirector::sharedDirector()->setContentScaleFactor(1.f);