Changing resource folder in accordance to the size of screen in Cocos2dx
Asked Answered
L

1

7

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.

Lowdown answered 12/9, 2013 at 9:50 Comment(0)
C
8

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);
         }
Camerlengo answered 12/9, 2013 at 9:53 Comment(1)
i have got issues with std::string searchPath;Lowdown

© 2022 - 2024 — McMap. All rights reserved.