예제 #1
0
void TestResolutionDirectories::onEnter()
{
    FileUtilsDemo::onEnter();
    CCFileUtils *sharedFileUtils = CCFileUtils::sharedFileUtils();

    string ret;
    
    sharedFileUtils->purgeCachedEntries();
    m_defaultSearchPathArray = sharedFileUtils->getSearchPaths();
    vector<string> searchPaths = m_defaultSearchPathArray;
    searchPaths.insert(searchPaths.begin(),   "Misc");
    sharedFileUtils->setSearchPaths(searchPaths);
    
    m_defaultResolutionsOrderArray = sharedFileUtils->getSearchResolutionsOrder();
    vector<string> resolutionsOrder = m_defaultResolutionsOrderArray;

    resolutionsOrder.insert(resolutionsOrder.begin(), "resources-ipadhd");
    resolutionsOrder.insert(resolutionsOrder.begin()+1, "resources-ipad");
    resolutionsOrder.insert(resolutionsOrder.begin()+2, "resources-widehd");
    resolutionsOrder.insert(resolutionsOrder.begin()+3, "resources-wide");
    resolutionsOrder.insert(resolutionsOrder.begin()+4, "resources-hd");
    resolutionsOrder.insert(resolutionsOrder.begin()+5, "resources-iphone");
    
    sharedFileUtils->setSearchResolutionsOrder(resolutionsOrder);
    
    for( int i=1; i<7; i++) {
        CCString *filename = CCString::createWithFormat("test%d.txt", i);
        ret = sharedFileUtils->fullPathForFilename(filename->getCString());
        CCLog("%s -> %s", filename->getCString(), ret.c_str());
    }
}
예제 #2
0
void CCApplication::setResourceRootPath(const std::string& rootResDir)
{
    m_resourceRootPath = rootResDir;
    if (m_resourceRootPath[m_resourceRootPath.length() - 1] != '/')
    {
        m_resourceRootPath += '/';
    }
    CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
    std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
    searchPaths.insert(searchPaths.begin(), m_resourceRootPath);
    pFileUtils->setSearchPaths(searchPaths);
}
예제 #3
0
void TestSearchPath::onEnter()
{
    FileUtilsDemo::onEnter();
    CCFileUtils *sharedFileUtils = CCFileUtils::sharedFileUtils();
    
    string ret;
    
    sharedFileUtils->purgeCachedEntries();
    m_defaultSearchPathArray = sharedFileUtils->getSearchPaths();
    vector<string> searchPaths = m_defaultSearchPathArray;
    string writablePath = sharedFileUtils->getWritablePath();
    string fileName = writablePath+"external.txt";
    char szBuf[100] = "Hello Cocos2d-x!";
    FILE* fp = fopen(fileName.c_str(), "wb");
    if (fp)
    {
        fwrite(szBuf, 1, strlen(szBuf), fp);
        fclose(fp);
        CCLog("Writing file to writable path succeed.");
    }
    
    searchPaths.insert(searchPaths.begin(), writablePath);
    searchPaths.insert(searchPaths.begin()+1,   "Misc/searchpath1");
    searchPaths.insert(searchPaths.begin()+2, "Misc/searchpath2");
    sharedFileUtils->setSearchPaths(searchPaths);
    
    m_defaultResolutionsOrderArray = sharedFileUtils->getSearchResolutionsOrder();
    vector<string> resolutionsOrder = m_defaultResolutionsOrderArray;
    
    resolutionsOrder.insert(resolutionsOrder.begin(), "resources-ipad");
    sharedFileUtils->setSearchResolutionsOrder(resolutionsOrder);
    
    for( int i=1; i<3; i++) {
        CCString *filename = CCString::createWithFormat("file%d.txt", i);
        ret = sharedFileUtils->fullPathForFilename(filename->getCString());
        CCLog("%s -> %s", filename->getCString(), ret.c_str());
    }
    
    // Gets external.txt from writable path
    string fullPath = sharedFileUtils->fullPathForFilename("external.txt");
    CCLog("\nexternal file path = %s\n", fullPath.c_str());
    if (fullPath.length() > 0) {
        fp = fopen(fullPath.c_str(), "rb");
        if (fp)
        {
            char szReadBuf[100] = {0};
            fread(szReadBuf, 1, strlen(szBuf), fp);
            CCLog("The content of file from writable path: %s", szReadBuf);
            fclose(fp);
        }
    }
}
예제 #4
0
    void AppDelegate::initGameView() {

        // initialize director
        CCDirector *pDirector = CCDirector::sharedDirector();
        pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
        pDirector->setProjection(kCCDirectorProjection2D);


        CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();
        if(!isPortraitApp) {
            screenSize = CCSizeMake(screenSize.height, screenSize.width);
        }

        std::vector<std::string> resDirOrders;
        std::string res;
        TargetPlatform platform = CCApplication::sharedApplication()->getTargetPlatform();


        if (platform == kTargetIphone || platform == kTargetIpad)
        {
            std::vector<std::string> searchPaths = CCFileUtils::sharedFileUtils()->getSearchPaths();
            searchPaths.insert(searchPaths.begin(), "Published files iOS");
            searchPaths.insert(searchPaths.begin(), getCCBDirectoryPath());

            CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);
            if (screenSize.height > 1136)
            {
                res = "iPad";
                setResolutionSizes(true, true, isPortraitApp);
                resDirOrders.push_back("resources-ipadhd");
                resDirOrders.push_back("resources-ipad");
                resDirOrders.push_back("resources-iphonehd");
                isIPhone = false;
                isRetina = true;
                cocos2d::extension::CCBReader::setResolutionScale(2);
            } else if(screenSize.height > 1024) {
                res = "iPhone";
                setResolutionSizes(false, true, isPortraitApp);
                resDirOrders.push_back("resources-iphonehd");
                resDirOrders.push_back("resources-iphone");
                isIPhone = true;
                isRetina = true;
            }
            else if (screenSize.height > 960)
            {
                res = "iPad";
                setResolutionSizes(true, false, isPortraitApp);
                resDirOrders.push_back("resources-ipad");
                resDirOrders.push_back("resources-iphonehd");
                isIPhone = false;
                isRetina = false;
                cocos2d::extension::CCBReader::setResolutionScale(2);

            }
            else if (screenSize.height > 480)
            {
                res = "iPhone";
                setResolutionSizes(false, true, isPortraitApp);
                resDirOrders.push_back("resources-iphonehd");
                resDirOrders.push_back("resources-iphone");
                isIPhone = true;
                isRetina = true;
            }
            else
            {
                res = "iPhone";
                setResolutionSizes(false, false, isPortraitApp);
                resDirOrders.push_back("resources-iphone");
                isIPhone = true;
                isRetina = false;
            }

        }
        else if (platform == kTargetAndroid || platform == kTargetWindows)
        {
            int dpi = -1;
            dpi = CCDevice::getDPI();

            if(dpi > 300) { // retina
                if (screenSize.height > 1920) {
                    res = "xlarge";
                    setResolutionSizes(true, true, isPortraitApp);
                    resDirOrders.push_back("resources-xlarge");
                    resDirOrders.push_back("resources-large");
                    resDirOrders.push_back("resources-medium");
                    resDirOrders.push_back("resources-small");
                } else {
                    res = "large";
                    setResolutionSizes(false, true, isPortraitApp);
                    resDirOrders.push_back("resources-large");
                    resDirOrders.push_back("resources-medium");
                    resDirOrders.push_back("resources-small");
                }
            } else { // non retina
                if (screenSize.height > 960)
                {
                    res = "large";
                    setResolutionSizes(true, false, isPortraitApp);
                    resDirOrders.push_back("resources-large");
                    resDirOrders.push_back("resources-medium");
                    resDirOrders.push_back("resources-small");
                    cocos2d::extension::CCBReader::setResolutionScale(2);
                }
                else if (screenSize.height > 768)
                {
                    res = "medium";
                    setResolutionSizes(true, false, isPortraitApp);
                    resDirOrders.push_back("resources-medium");
                    resDirOrders.push_back("resources-small");
                }
                else if (screenSize.height > 480)
                {
                    res = "small";
                    setResolutionSizes(false, false, isPortraitApp);
                    resDirOrders.push_back("resources-small");
                }
                else
                {
                    setResolutionSizes(false, false, isPortraitApp);
                    res = "xsmall";
                    resDirOrders.push_back("resources-xsmall");
                }

            }
        }

        CCFileUtils *pFileUtils = CCFileUtils::sharedFileUtils();
        pFileUtils->setSearchResolutionsOrder(resDirOrders);

        std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
        searchPaths.insert(searchPaths.begin(), pFileUtils->getWritablePath());
        pFileUtils->setSearchPaths(searchPaths);

        PlayerStatus::setDeviceResolution(res);
        // turn on display FPS
        pDirector->setDisplayStats(true);

        // set FPS. the default value is 1.0/60 if you don't call this
        pDirector->setAnimationInterval(1.0 / 60);
    }