Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing resource folder in accordance to the size of screen in Cocos2dx

Tags:

cocos2d-x

I'm using Xcode IDE and Cocos2dx for developing multi platform game. i have just started development and 'm stuccoed at one place. I want to change the resource folder in accordance to the size of the screen.

CCSize screenSize = pEGLView->getFrameSize();
       CCEGLView::sharedOpenGLView()->setDesignResolutionSize(768, 1024,
       kResolutionExactFit);
       if (screenSize.width > 768) {

          CCFileUtils::sharedFileUtils()->setResourceDirectory("hd");

          pDirector->setContentScaleFactor(2);
      } else {

          CCFileUtils::sharedFileUtils()->setResourceDirectory("sd");

          pDirector->setContentScaleFactor(1);
       }

but since the setResourceDirectory() is deprecated i can use any other method. I tried using setSearchPaths() but its giving errors. please let me know if anyone have the same thing working. Thanks in advance.

like image 664
Rishabh Srivastava Avatar asked Sep 12 '13 09:09

Rishabh Srivastava


1 Answers

okay, since setDesignResolutionSize() is deprecated we need to use setSearchPaths() you can have something like this, Its working in my case:

    CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();    
    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(768, 1024,
                                                           kResolutionExactFit);
     std::vector<std::string> searchPaths;

         if (screenSize.width > 768) {
             searchPaths.push_back("hd");
             CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);        
             pDirector->setContentScaleFactor(2);
         }else{
             searchPaths.push_back("sd");
             CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);
             pDirector->setContentScaleFactor(1);
         }
like image 70
Ravi_Parmar Avatar answered Sep 27 '22 18:09

Ravi_Parmar