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());
    }
}
void TestSearchPath::onExit()
{
	CCFileUtils *sharedFileUtils = CCFileUtils::sharedFileUtils();

	// reset search path
	sharedFileUtils->setSearchPaths(m_defaultSearchPathArray);
    sharedFileUtils->setSearchResolutionsOrder(m_defaultResolutionsOrderArray);
    FileUtilsDemo::onExit();
}
Exemple #3
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);
}
Exemple #4
0
XFileAssist::XFileAssist()
{
    CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
    
    std::string strWritePath = pFileUtils->getWritablePath();
    
    std::vector<std::string> pathTable;
    
    pathTable.push_back(strWritePath);
    
    pFileUtils->setSearchPaths(pathTable);
}
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);
        }
    }
}
Exemple #6
0
bool AppDelegate::applicationDidFinishLaunching()
{
	// As an example, load config file
	// XXX: This should be loaded before the Director is initialized,
	// XXX: but at this point, the director is already initialized
	CCConfiguration::sharedConfiguration()->loadConfigFile("configs/config-example.plist");

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

    CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();

    CCSize designSize = CCSizeMake(480, 320);

    CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
    std::vector<std::string> searchPaths;
    
	if (screenSize.height > 320)
    {
        CCSize resourceSize = CCSizeMake(960, 640);
        searchPaths.push_back("hd");
		searchPaths.push_back("hd/scenetest");
        pDirector->setContentScaleFactor(resourceSize.height/designSize.height);
    }
	else
	{
		searchPaths.push_back("scenetest");
	}
	pFileUtils->setSearchPaths(searchPaths);

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionShowAll);
#else
	CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);
#endif

    CCScene * pScene = CCScene::create();
    CCLayer * pLayer = new TestController();
    pLayer->autorelease();

    pScene->addChild(pLayer);
    pDirector->runWithScene(pScene);

    return true;
}
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);
    
    CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();
    
    CCSize designSize = CCSizeMake(480, 320);
    
    CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
    
    
    if (screenSize.height > 320)
    {
        CCSize resourceSize = CCSizeMake(960, 640);
        std::vector<std::string> searchPaths;
        searchPaths.push_back("hd");
        pFileUtils->setSearchPaths(searchPaths);
        pDirector->setContentScaleFactor(resourceSize.height/designSize.height);
    }
    
    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionShowAll);
	
    // 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);

    // create a scene. it's an autorelease object
//    CCScene *pScene = HelloWorld::scene();
    CocosGUIExamplesRegisterScene *pScene = new CocosGUIExamplesRegisterScene();
    pScene->autorelease();

    // run
    pDirector->runWithScene(pScene);

    return true;
}
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());

    CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();

#ifdef TIZEN
    CCSize designSize = CCSizeMake(1280, 720);
#else
    CCSize designSize = CCSizeMake(480, 320);
#endif
    CCFileUtils* pFileUtils = CCFileUtils::sharedFileUtils();
    
    if (screenSize.height > 320)
    {
        CCSize resourceSize = CCSizeMake(960, 640);
        std::vector<std::string> searchPaths;
        searchPaths.push_back("hd");
        pFileUtils->setSearchPaths(searchPaths);
        pDirector->setContentScaleFactor(resourceSize.height/designSize.height);
    }

    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);

    // 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);

    CCScene * pScene = CCScene::create();
    CCLayer * pLayer = new TestController();
    pLayer->autorelease();

    pScene->addChild(pLayer);
    pDirector->runWithScene(pScene);

    return true;
}
Exemple #9
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);
    }
Exemple #10
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
    
    CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize();
    CCFileUtils *pFileUtils = CCFileUtils::sharedFileUtils();
    std::vector<std::string> searchPaths;
    
    CCSize designSize = CCSizeMake(480, 320);
    CCSize resourceSize;
    
    // if the device is iPad
    if (screenSize.height >= 768) {
        searchPaths.push_back("hd");
        searchPaths.push_back("sd");
        
        resourceSize = CCSizeMake(1024, 768);
        designSize = CCSizeMake(1024, 768);
    }
    // if the device is iPhone
    else{
        // for retina iPhone
        if (screenSize.height > 320) {
            searchPaths.push_back("hd");
            searchPaths.push_back("sd");
            resourceSize = CCSizeMake(960, 640);
            
          
        }
        else{
            searchPaths.push_back("sd");
            resourceSize = CCSizeMake(480, 320);
        }
    }
    searchPaths.push_back("WhackAMoleSounds");
    pFileUtils->setSearchPaths(searchPaths);
    pDirector->setContentScaleFactor(resourceSize.width / designSize.width);
    
    
    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionFixedWidth);
    
    // load background and foreground
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("background.plist");
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("foreground.plist");

    // 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);

    // create a scene. it's an autorelease object
    CCScene *pScene = HelloWorld::scene();

    // run
    pDirector->runWithScene(pScene);

    return true;
}