Question

How do I set-up the SD, HD, HDR, etc directories in my Cocos2d-x 3.0 project such that I can run on Android and iOS?

My set-up on a previous project using Cocos2d-x 2.x relies on parts of the API that are deprecated in 3.0. The Cocos2d-x docs are incomplete. The cpp test project that's bundled w/ 3.0 doesn't help either.

Any info is helpful.

Was it helpful?

Solution

Make 4 directories in resource folder "hdpi","mdpi","ldpi","xhdpi" and put the respective images in those directories. Now there are two methods to do this:

First

  if(Device::getDPI()<=120)
    FileUtils::sharedFileUtils()->setSearchPaths("ldpi");

  else if(Device::getDPI()<=160)
    FileUtils::sharedFileUtils()->setSearchPaths("mdpi");

  else if(Device::getDPI()<=240)
    FileUtils::sharedFileUtils()->setSearchPaths("hdpi");

  else if(Device::getDPI()<=320)
    FileUtils::sharedFileUtils()->setSearchPaths("xhdpi");

Second Method

       Size winSize = CCDirector::sharedDirector()->getWinSize();
       // Portrait
       if ( winSize.width <= 240 && winSize.height<=320 ) 
           FileUtils::sharedFileUtils()->setSearchPaths("ldpi");

       else if ( winSize.width <= 320 && winSize.height<=480 ) 
            FileUtils::sharedFileUtils()->setSearchPaths("mdpi");

       else if( winSize.width <= 480 && winSize.height<=800 ) 
            FileUtils::sharedFileUtils()->setSearchPaths("hdpi");

       else
            FileUtils::sharedFileUtils()->setSearchPaths("xhdpi");

You call the above code from your AppDelegate::applicationDidFinishLaunching() function to tell Cocos2d-x to use the correct subdirectory for resources.

I have tested it on cocos2d-x 3.1 and it worked for me. I hope it will work for you.

OTHER TIPS

have you tried this?

FileUtils::getInstance()->addSearchPath("hd"); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top