GiZmo
March 15, 2014, 12:33pm
#1
Hi,
I am struggling with setting the multi resolution for both iOS and Android. I created the textures my application using 1024x768 resolution as a reference. I used TexturePacker to generate the HDR, HD and SD files. I am using Cocos2d-X version 2.2.1
My problem is that I cannot manage to configure the application properly. The code that I am using is this
`CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();
CCFileUtils *pFileUtils = CCFileUtils::sharedFileUtils();
std::vectorstd::string searchPaths;
CCSize designSize = CCSize(1024, 768);
CCSize resourceSize;
// if the device is iPad
if (screenSize.height >= 768)
{
searchPaths.push_back("HDR");
searchPaths.push_back("HD");
searchPaths.push_back("SD");
resourceSize = CCSizeMake(1024, 768);
designSize = CCSizeMake(1024, 768);
}
// if the device is iPhone
else
{
// for retina iPhone
if (screenSize.height > 320)
{
searchPaths.push_back("HD");
searchPaths.push_back("SD");
resourceSize = CCSizeMake(960, 640);
}
else
{
searchPaths.push_back("SD");
resourceSize = CCSizeMake(480, 320);
}
}
searchPaths.push_back("Sounds");
searchPaths.push_back("Images");
searchPaths.push_back("Fonts");
pFileUtils->setSearchPaths(searchPaths);
pDirector->setContentScaleFactor(resourceSize.width / designSize.width);
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionFixedWidth);`
I also tried to follow some tutorials such as this and this , but so far I am not able to make the stuff working.
Does anyone knows what should I do to support multi resolution for both iOS and Android?
Thanks a lot in advance
My english is really bad, so let’s code speak. First of all, some constants will help:
typedef struct tagResource {
cocos2d::CCSize size;
char directory[100];
} Resource;
static Resource smallResource = { cocos2d::CCSizeMake(480, 320), "SD" };
static Resource mediumResource = { cocos2d::CCSizeMake(960, 640), "HD" };
static Resource largeResource = { cocos2d::CCSizeMake(1024, 768), "HDR" };
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(1024, 768);
Now in applicationDidFinishLaunching(), you can proceed as follow:
CCSize frameSize = pEGLView->getFrameSize();
// Set the design resolution
pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionFixedWidth);
std::vector<std::string> searchPaths;
if (frameSize.height <= smallResource.size.height) {
searchPaths.push_back(smallResource.directory);
CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);
pDirector->setContentScaleFactor(smallResource.size.height/designResolutionSize.height);
} else if (frameSize.height <= mediumResource.size.height) {
searchPaths.push_back(mediumResource.directory);
CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);
pDirector->setContentScaleFactor(mediumResource.size.height/designResolutionSize.height);
} else{
searchPaths.push_back(largeResource.directory);
CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);
pDirector->setContentScaleFactor(largeResource.size.height/designResolutionSize.height);
}
GiZmo
March 15, 2014, 11:14pm
#3
@icaroinflames
Thanks a lot for your answer. I tried your code but it does not work. Honestly, I don’t get it. If you compare my code with your code it is exactly the same stuff.
I am also sure that I configure correctly TexturePacker. I selected the Data Format as cocos2d, and in the Auto SD I selected cocos2d-x HDR/HD/SD.
This issue is driving me crazy, since I am following exactly the same code as everyone is using :;fury
Does anyone else has the issue as I do?
Thanks a lot
Do you have your SD and HD directories in the right location on your file system, etc.
Example, on OS X I have to have an SD and HD directory in my Resources/ directory.
GiZmo
March 16, 2014, 7:09am
#5
@slackmoehrle
Hi
Yes, I have the directories under Resources.
For the moment, I plan to do
CCSize designSize = CCSize(1024, 768);
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionFixedWidth);
And use only one texture for all the resolution.
I know it is not the most elegant solution, but it works. I will keep digging with this issue on v3.0
Make your self a coffee .
and read this document also , its less known one in the Cocos2d-x documentations
http://www.cocos2d-x.org/wiki/Detailed_explanation_of_Cocos2d-x_Multi-resolution_adaptation
also please
Take a look at the HelloCpp example , Specially the AppMacros.h file , there is info in the comments there .
also if you read about the term Playable rectangle ( visible area )
take a look at the files VisibleRect.h/cpp in the TestCpp tree .
please remember there is no perfect solution to screen fragmentation you will have to hack
something in between
GiZmo
March 16, 2014, 6:38pm
#7
@Meir_yanovich
Thanks a lot, I will have a look