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.