Cocos2d-x and CocosBuilder multi-resolution for ios and android

I follow the instruction in the link below can get multi-resolution work on ios platform without cocosBuilder.
http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Multi_resolution_support

When I use cocosbuilder ccbi file, the images displayed on the ipad screen are still iphone image.

cocosbuilder publish the resource directory like this

but it seems like cocos2d-x does not pick the right images for the right resolution from the right directory.

Here is my resource setting in the code. I am testing it on ipad 3 with HD.

#define DESIGN_RESOLUTION_480X320 0
#define DESIGN_RESOLUTION_1024X768 1
#define DESIGN_RESOLUTION_2048X1536 2

/* If you want to switch design resolution, change next line /
#define TARGET_DESIGN_RESOLUTION_SIZE DESIGN_RESOLUTION_2048X1536
typedef struct tagResource
{
cocos2d::CCSize size;
char directory[100];
}Resource;
static Resource smallResource = { cocos2d::CCSizeMake, “ccb/resources-iphone” };
static Resource mediumResource = { cocos2d::CCSizeMake, “ccb/resources-ipad” };
static Resource largeResource = { cocos2d::CCSizeMake, “ccb/resources-ipadhd” };
#if
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake;
#elif
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake;
#elif
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake;
#else
#error unknown target design resolution!
#endif
// The font size 24 is designed for small resolution, so we should change it to fit for current design resolution
#define TITLE_FONT_SIZE ->getDesignResolutionSize.width / smallResource.size.width
24)

#endif /* APPMACROS_H */


res-pub.png (77.3 KB)

What’s the code in your AppDelegate.cpp ? By that I mean when you set CCFileUtils::sharedFileUtils()->setResourceDirectory and the CCDirector content scale factor.

François Dupayrat wrote:

What’s the code in your AppDelegate.cpp ? By that I mean when you set CCFileUtils::sharedFileUtils()>setResourceDirectory and the CCDirector content scale factor.
Hi Francois:
Here is my code in AppDelegate.cpp
bool AppDelegate::applicationDidFinishLaunching {
// initialize director
CCDirector* pDirector = CCDirector::sharedDirector;
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView;
pDirector
>setOpenGLView(pEGLView);

// Set the design resolution
pEGLView~~>setDesignResolutionSize;
CCSize frameSize = pEGLView~~>getFrameSize();

vector searchPath;

// 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 > mediumResource.size.height)
{
searchPath.push_back(largeResource.directory);

////pDirector~~>setContentScaleFactor);
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)
{
searchPath.push_back(mediumResource.directory);

pDirector~~>setContentScaleFactor);
}
// if the frame’s height is smaller than the height of medium resource size, select small resource.
else
{
searchPath.push_back;
pDirector~~>setContentScaleFactor(MIN (smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
}
// set searching path
CCFileUtils::sharedFileUtils()>setSearchPaths;
// turn on display FPS
pDirector
>setDisplayStats(true);

// set FPS. the default value is 1.0/60 if you don’t call this
pDirector~~>setAnimationInterval;
// create a scene. it’s an autorelease object
//CCScene pScene = HelloWorld::scene;
MainMenuScene
pScene = new MainMenuScene;
pScene~~>runScene();
// run
pDirector->runWithScene(pScene);
return true;
}

There is a problem with the code you copy-pasted. But anyway, can you confirm, using breakpoints, of the 3 “searchPath.push_back”, only the one with largeResource.directory is called ?

Another important thing : which cocos2d-x version are you running ?

Hi Francois:

I using the breakpoint and the app only called searchPath.push_back(largeResource.directory);

Here is the print out about the value of searchPath

(std::vector<std::basic_string<char, std::char_traits, std::allocator >, std::allocator<std::basic_string<char, std::char_traits, std::allocator > > >) $1 = size=1 {
(std::basic_string<char, std::char_traits, std::allocator >) [0] = “ccb/resources-ipadhd”
}

The cocos2d-x is 2.1.2 version and cocosBuilder is 3.0

François Dupayrat wrote:

There is a problem with the code you copy-pasted. But anyway, can you confirm, using breakpoints, of the 3 “searchPath.push_back”, only the one with largeResource.directory is called ?
>
Another important thing : which cocos2d-x version are you running ?

Seems I won’t be able to help you much more, since I use cocos2d-x 2.0.4 and CocosBuilder 2.1.

Just a last thought : on CocosBuilder, did you properly set your sprite scale on multiply by resolution scale ? The problem may be that it loads the right sprite, but the scale is wrong. You can also manually check the sprite scale at runtime to make sure of this.

Thank you Francois, You are the only replied my question. I asked on cocos2d-iphone and stackoverflow too. But it seems like no one had the experience with the latest release.

I will continue dig down more and if I find the solution, I will post it here.

François Dupayrat wrote:

Seems I won’t be able to help you much more, since I use cocos2d-x 2.0.4 and CocosBuilder 2.1.
>
Just a last thought : on CocosBuilder, did you properly set your sprite scale on multiply by resolution scale ? The problem may be that it loads the right sprite, but the scale is wrong. You can also manually check the sprite scale at runtime to make sure of this.

the problem is that about the latest release cocos2d-x and cocosbuilder are not using the same resource directories.

I had to manually setup the cocosbuilder CCBReader file path. Now it is working.

François Dupayrat wrote:

Seems I won’t be able to help you much more, since I use cocos2d-x 2.0.4 and CocosBuilder 2.1.
>
Just a last thought : on CocosBuilder, did you properly set your sprite scale on multiply by resolution scale ? The problem may be that it loads the right sprite, but the scale is wrong. You can also manually check the sprite scale at runtime to make sure of this.