multi-resolution support, why this doesn't work?


#1

Hi, here is my res file structure. In my res file, I have iphone, iphonehd, iphonehd5, ipad,ipadhd…

I created sprite like this: cc.Sprite.create(“res/background.png”).

so, my current structure is like:

res
-------iphone
…|…res
…|…background.png
-------ipad
…|…res
…|…background.png
-------iphonehd
…|…res
…|…background.png
-------ipadhd
…|…res
…|…background.png
--------iphone5hd
…|…res
…|…background.png

when I run it in ipad simulator, it can’t pick up the image inside that folder. What’s the possible problem is?

below is the code I used to determine multi-resolution:

 pDirector->setOpenGLView(pEGLView);
    CCSize frame_size = pEGLView->getFrameSize();
    std::vector<std::string> res_dir_orders;
    
    
    if(2048 == frame_size.height){
        CCLog("I am inside 1");
        res_dir_orders.push_back("ipadhd");
        res_dir_orders.push_back("ipad");
        res_dir_orders.push_back("iphonehd5");
        res_dir_orders.push_back("iphonehd");
        res_dir_orders.push_back("iphone");
        
    }
    
    else if(1024 == frame_size.height)
    {
        CCLog("I am inside 2");
        res_dir_orders.push_back("ipad");
        res_dir_orders.push_back("iphonehd5");
        res_dir_orders.push_back("iphonehd");
        res_dir_orders.push_back("iphone");
        
    }
    else if(1136 == frame_size.height)
    {
        CCLog("I am inside 3");
        res_dir_orders.push_back("iphonehd5");
        res_dir_orders.push_back("iphonehd");
        res_dir_orders.push_back("iphone");
    }
    
    else if(960 == frame_size.height)
    {
        CCLog("I am inside 4");
        res_dir_orders.push_back("iphonehd");
        res_dir_orders.push_back("iphone");
        
    }else{
        CCLog("I am inside 5");
        res_dir_orders.push_back("iphone");
        
    }
    
    CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(res_dir_orders);

#2

how are you referencing the image in your code, also what orientation is your simulator in as this will only work for portrait, check for the width as well

e.g.
(2048 == frame_size.height || 2048 == frame_size.width)
(1024 == frame_size.height || 1024 == frame_size.width)
(1136 == frame_size.height || 1136 == frame_size.width)
(640 == frame_size.height || 640 == frame_size.width)


#3

my bad last one should be 960 not 640


#4

@SonarSystems

Hi, thanks for your reply. Actually those codes are from you but I modified it. : )

Mine is a portrait app. And I saw CCLog(“I am inside 2”); in console when I test it on iPad none-retina.

also, I created sprite like this:

cc.Sprite.create(“res/background.png”).

But looks like it doesn’t pick up the desired images assets.


#5

@cocos2dx
you need to do res/res/background.png, or remove the second res folder so your folder structure is as follows, res/iphoneorwhateverdevice/background.png, we recommend the second method unless you have a particular reason for the secondary res folder

hope that helps, let us know if you have any issues.