Search code examples
ioscocos2d-x

How to setup Cocos2d-x image resources properly


I can't seem to get my retina / non retina images to display properly. With cocos2d changing the syntax often, I'm not sure what to use anymore.

I have tried tutorials like this one, but nothing seems to work.

My current resources are set up to sd & hd folders in the Resources directory (both versions of images have the same name, i've tried adding suffixes), I would like to pull the appropriate image for nonretina/retina iPad in cocos2d-x.

What is the current cocos2dx syntax to set directories? Do i have to set a specific suffix along with setting a directory? Please help.
Cocos2d-x v2.2

EDIT**
I'm testing on retina & nonretina ipad. If I include only non retina images its perfect on non retina iPad, and everything is tiny on retina as expected. Now when i add retina images to the project, the devices get confused and load random sizes, etc one image is retina, next one is non retina. This is because both versions have the same filename, but i have them in different directories Resouces/sd & Resources/hd. How do i set the cocos2dx v2.2.2 project to load from the appropriate directory? I've tried many tutorials and the cocos2dx example, they're not working for me.


Solution

  • So after many, many frustrating hours of trial and error, I've figured it out!
    What i was doing wrong was importing hd & sd folders as Groups instead of Folder references..
    See this post for details

    Then I simply did this, and works perfectly non/retina & retina iPad:

    AppDelegate.ccp
    
    bool AppDelegate::applicationDidFinishLaunching() {
        CCDirector* pDirector = CCDirector::sharedDirector();
        CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
        pDirector->setOpenGLView(pEGLView);
    
        vector<string> searchPath;
        CCSize frameSize = pEGLView->getFrameSize();
    
       if (frameSize.height > 1024)
           searchPath.push_back("hd");
       else
           searchPath.push_back("sd");
       CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath);
    
       ...
    }
    

    Hope this saves somebody the trouble!