0

I am facing this problem of random output of my application at each launch in xcode simulator. I am using xCode Version 4.6.3 . I tried and executed all the steps mentioned in here How to Empty Caches and Clean All Targets Xcode 4 but it didn't help. I am using different resources for different family of devices. (Basically I am making universal iOs app.). Please check below code which I am using in AppDelegate.cpp

CCSize screenSize = pEGLView->getFrameSize();

//set design size for iPad retina

CCSize designSize = CCSize(1536,2048); //1.33

float screenRatio = screenSize.height/screenSize.width;

std::vector<std::string> searchPaths;

if (screenSize.width > 768)
{
    searchPaths.push_back("ipadRetina");
}
else if (screenSize.width > 320)
{
    if (screenRatio == 1.5f) // && screenRatio < 1.775f)
    {
        searchPaths.push_back("iphoneRetina");
        designSize = CCSize(640,960);       
    }
    else if(screenRatio == 1.775f)
    {
        searchPaths.push_back("iphoneFive");
        designSize = CCSize(640,1136);
              }
    else
    {
        searchPaths.push_back("ipad");

    }
}
else
{
    searchPaths.push_back("iphone");
    designSize = CCSize(320,480);

}


CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionShowAll);
CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);
pDirector->setContentScaleFactor(screenSize.height/designSize.height);

Output each time I'm getting is completely random.Sometimes images coming are with extra zoom, after that, if I close the project and rerun it, output (images) comes shrinked. On Next run it comes completely different than previous two outputs.

What I observed from above code is when I am trying to run application for ipadRetina it takes resources,sometimes from iphone folder,sometimes from ipadRetina folder.. but when I put the breakpoint,searchpath is set for ipadRetina folder.

Please help.

Community
  • 1
  • 1
Deva
  • 48
  • 6

2 Answers2

0

Seems like there are multiple resources in your project tree with same name. Xcode is just getting confused when you refer an image named my-image.png and there are multiple images with that name in your project.

A good way to avoid this type of issues is to have unique resource names like:

game-image.png (for iPhone)
game-image-hd.png (for iPhone Retina)
game-image-ipad.png (for iPad)
game-image-ipad-hd.png (for iPad Retina)
nomann
  • 2,257
  • 2
  • 21
  • 24
  • What Eklavya saying, is correct. I'm maintaining different folders for different resolution devices. Above code I wrote is picking up the correct folder according to resolution through search path. Rather I needed same names for all resolution resources,so that I can handle them through generalised code. – Deva Oct 16 '13 at 06:35
  • Deva, if that's not the case. May be this is not an issue with your resources but with calculated design resolution. I can clearly see that you are not assigning any values in 'designSize' when the device is iPad or iPad retina. You might end up passing garbage values in 'setDesignResolutionSize'. – nomann Oct 17 '13 at 17:17
  • Thanks for the reply Nomannasim..I have written designSize globaly and assigning value with respect to device afterwards so that was not the problem..the solution I got for this problem is mentioned here, do check section 2.4 of http://www.cocos2d-x.org/wiki/Mechanism_of_loading_resources – Deva Oct 18 '13 at 14:42
-1

Although its not the answer but I could not find a way to add it as a comment. @nomannasim I think that should not be the problem , as Deva is maintaining different folders for different resolution devices and which folder is selected depends on the width and aspect ratio of the device on which app is running.So any how only one folder's path is going to be set in searchPath of CCFileUtils::sharedFileUtils(). So no confusion in picking up resources.

Eklavyaa
  • 370
  • 5
  • 17