Ejemplo n.º 1
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
        glview = GLViewImpl::createWithRect("flappyRocket", Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
        glview = GLViewImpl::create("flappyRocket");
#endif
        director->setOpenGLView(glview);
    }
    
    // Set the design resolution
    auto fileUtils = FileUtils::getInstance();
    auto screenSize = glview->getFrameSize();
    std::vector<std::string> resDirOrders;
    
    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::FIXED_HEIGHT);
    Size frameSize  = glview->getFrameSize();
    // if the frame's height is larger than the height of medium size.
    if (frameSize.height > mediumResolutionSize.height)
    {
        resDirOrders.push_back("HD");
        resDirOrders.push_back("SD");
        director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
    }
    else
    {   resDirOrders.push_back("SD");
        director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
    }

    
    register_all_packages();
    
    fileUtils->setSearchPaths(resDirOrders);


    // create a scene. it's an autorelease object
    auto scene = SplashScene::createScene();

    // run
    director->runWithScene(scene);

    return true;
}
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLView::create("My Game");
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(true);

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

    auto screenSize = glview->getFrameSize();
    
    auto designSize = Size(480, 320);
    
    auto fileUtils = FileUtils::getInstance();
    std::vector<std::string> searchPaths;
    
    if (screenSize.height > 320)
    {
        auto resourceSize = Size(960, 640);
        searchPaths.push_back("hd");
        director->setContentScaleFactor(resourceSize.height/designSize.height);
    }
    
    fileUtils->setSearchPaths(searchPaths);
    
    //    glview->setDesignResolutionSize(screenSize.width, screenSize.height, ResolutionPolicy::NO_BORDER);
    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
    
    
    // create a scene. it's an autorelease object
    auto scene = new CocosGUIExamplesEquipScene();
    scene->autorelease();
    // run
    director->runWithScene(scene);

    return true;
}
Ejemplo n.º 3
0
void FileUtils::setDefaultResourceRootPath(const std::string& resRootPath)
{
    if (_defaultResRootPath == resRootPath)
        return;

    if (!_searchPathArray.empty() && !_defaultResRootPath.empty())
    {
        auto tmp = _defaultResRootPath.length();
        for (auto& iter : _searchPathArray)
        {
            iter = iter.substr(tmp);
        }
        _defaultResRootPath = resRootPath;
        setSearchPaths(_searchPathArray);
    }
    else
    {
        _defaultResRootPath = resRootPath;
    }
}
Ejemplo n.º 4
0
void FileUtilsLayer::OnClickMenu6(Ref* pSender)
{
    
    auto sharedFileUtils = FileUtils::getInstance();
    
    sharedFileUtils->purgeCachedEntries();
    
    std::vector<std::string> searchPaths = sharedFileUtils->getSearchPaths();
    std::string writablePath = sharedFileUtils->getWritablePath();
    
    searchPaths.insert(searchPaths.begin(), "dir1");
    searchPaths.insert(searchPaths.begin()+1, writablePath);
    sharedFileUtils->setSearchPaths(searchPaths);
    
    std::string fullPathForFilename = sharedFileUtils->fullPathForFilename("test.txt");
    log("test.txt 's fullPathForFilename is : %s",fullPathForFilename.c_str());
    
    Data data = sharedFileUtils->getDataFromFile(fullPathForFilename);
    std::string content = sharedFileUtils->getStringFromFile(fullPathForFilename);
    log("File content is : %s",content.c_str());
}
Ejemplo n.º 5
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    CCLog("director = %f",_director->getContentScaleFactor());
    
    _director->setContentScaleFactor(1);
    
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    Size winSize = Director::getInstance()->getWinSize();
    
    //设置优先加载资源文件
    auto fileUtils = FileUtils::getInstance();
    
    std::vector<std::string> searchPaths;
    searchPaths.push_back("Armature");
    
    
    fileUtils->setSearchPaths(searchPaths);
   
    //播放骨头动画
    std::string RootResource = CResourceData::sharedResourceData()->getArmatureResource();
    
    std::string IphoneResource = CResourceData::sharedResourceData()->getIphoneResource();
    
    std::string xml = RootResource + "agathelos.xml";
    
    std::string img = RootResource + "agathelos.png";
    
    std::string plist = RootResource + "agathelos.plist";
    
    std::string str_json = RootResource + "HeroAnimation.ExportJson";
    
    std::string str_cbs = RootResource + "HeroAnimation.csb";
    
    
    ArmatureDataManager::getInstance()->addArmatureFileInfo(img.c_str(), plist.c_str(), xml.c_str());
    
    //ArmatureDataManager::getInstance()->addArmatureFileInfo(str_json.c_str());
//    armature.width = 188.439743,armature.height = 216.856171
//    armature.width = 130.217926,armature.height = 161.162491
    
    Armature * armature = Armature::create("agathelos");
    armature->getAnimation()->play("hurt");
    armature->getAnimation()->setSpeedScale(0.4f);
    armature->setPosition(VisibleRect::center().x, VisibleRect::center().y * 0.3f);
    
    addChild(armature,100);
    
    
    //添加动画监听
    //armature->getAnimation()->setMovementEventCallFunc(CC_CALLBACK_0(HelloWorld::animationEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
    

    
    std::string backPath = RootResource + "ask_skirmish_back.pvr.ccz";
    
    Sprite * backGround = Sprite::create(backPath.c_str());
    backGround->setPosition(VisibleRect::center().x,VisibleRect::center().y);
    backGround->setAnchorPoint(Vec2(0.5, 0.5));
    backGround->setVisible(true);
    this->addChild(backGround,10);
    
    
    CCLog("sprite width = %f",backGround->getContentSize().width);
    
    CCLog("ContentScaleFactor = %f",_director->getContentScaleFactor());
    
    return true;
}
Ejemplo n.º 6
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
        glview = GLViewImpl::createWithRect("WackyBirds", Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
        glview = GLViewImpl::create("WackyBirds");
#endif
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(true);

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

    // Set the design resolution
    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
    Size frameSize = glview->getFrameSize();
    // if the frame's height is larger than the height of medium size.
    if (frameSize.height > mediumResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is larger than the height of small size.
    else if (frameSize.height > smallResolutionSize.height)
    {        
        director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is smaller than the height of medium size.
    else
    {        
        director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
    }


// multi platform resolution
        auto fileUtils = FileUtils::getInstance();
        auto screenSize = glview->getFrameSize();
        std::vector<std::string> resDirOrders;
    
    // check which assets the devices requires
    if ( 2048 == screenSize.width || 2048 == screenSize.height ) // retina iPad
    {
        resDirOrders.push_back("ipadhd");
        resDirOrders.push_back("ipad");
        resDirOrders.push_back("iphonehd5");
        resDirOrders.push_back("iphonehd");
        resDirOrders.push_back("iphone");
        
        glview->setDesignResolutionSize(1536, 2048, ResolutionPolicy::NO_BORDER);
    }
    else if ( 1024 == screenSize.width || 1024 == screenSize.height ) // non retina iPad
    {
        resDirOrders.push_back("ipad");
        resDirOrders.push_back("iphonehd5");
        resDirOrders.push_back("iphonehd");
        resDirOrders.push_back("iphone");
        
        glview->setDesignResolutionSize(768, 1024, ResolutionPolicy::NO_BORDER);
    }
    else if ( 1136 == screenSize.width || 1136 == screenSize.height ) // retina iPhone (5 and 5S)
    {
        resDirOrders.push_back("iphonehd5");
        resDirOrders.push_back("iphonehd");
        resDirOrders.push_back("iphone");
        
        glview->setDesignResolutionSize(640, 1136, ResolutionPolicy::NO_BORDER);
    }
    else if ( 960 == screenSize.width || 960 == screenSize.height ) // retina iPhone (4 and 4S)
    {
        resDirOrders.push_back("iphonehd");
        resDirOrders.push_back("iphone");
        
        glview->setDesignResolutionSize(640, 960, ResolutionPolicy::NO_BORDER);
    }
    else // non retina iPhone and Android devices
    {
        if ( 1080 < screenSize.width ) // android devices that have a high resolution
        {
            resDirOrders.push_back("iphonehd");
            resDirOrders.push_back("iphone");
            
            glview->setDesignResolutionSize(640, 960, ResolutionPolicy::NO_BORDER);
        }
        else // non retina iPhone and Android devices with lower resolutions
        {
            resDirOrders.push_back("iphone");
            
            glview->setDesignResolutionSize(320, 480, ResolutionPolicy::NO_BORDER);
        }
    }
    
    fileUtils->setSearchPaths(resDirOrders);
// end multi platform resolution




    register_all_packages();

    // create a scene. it's an autorelease object
    auto scene = SplashScene::createScene();

    // run
    director->runWithScene(scene);

    return true;
}
Ejemplo n.º 7
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("Get To The Lander");
        director->setOpenGLView(glview);
    }
    
    // turn on display FPS
    director->setDisplayStats(false);
    
    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    auto fileUtils = FileUtils::getInstance( );
    auto screenSize = glview->getFrameSize( );
    std::vector<std::string> resDirOrders;
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	// check which assets the devices requires
	if (2048 == screenSize.width || 2048 == screenSize.height) // retina iPad
	{
		resDirOrders.push_back("ipadhd");
		resDirOrders.push_back("ipad");
		resDirOrders.push_back("iphonehd5");
		resDirOrders.push_back("iphonehd");
		resDirOrders.push_back("iphone");

		if (true == IS_LANDSCAPE)
		{
			glview->setDesignResolutionSize(2048, 1536, ResolutionPolicy::NO_BORDER);
		}
		else
		{
			glview->setDesignResolutionSize(1536, 2048, ResolutionPolicy::NO_BORDER);
		}
	}
	else if (1024 == screenSize.width || 1024 == screenSize.height) // non retina iPad
	{
		resDirOrders.push_back("ipad");
		resDirOrders.push_back("iphonehd5");
		resDirOrders.push_back("iphonehd");
		resDirOrders.push_back("iphone");

		if (true == IS_LANDSCAPE)
		{
			glview->setDesignResolutionSize(1024, 768, ResolutionPolicy::NO_BORDER);
		}
		else
		{
			glview->setDesignResolutionSize(768, 1024, ResolutionPolicy::NO_BORDER);
		}
	}
	else if (1136 == screenSize.width || 1136 == screenSize.height) // retina iPhone (5 and 5S)
	{
		resDirOrders.push_back("iphonehd5");
		resDirOrders.push_back("iphonehd");
		resDirOrders.push_back("iphone");

		if (true == IS_LANDSCAPE)
		{
			glview->setDesignResolutionSize(1136, 640, ResolutionPolicy::NO_BORDER);
		}
		else
		{
			glview->setDesignResolutionSize(640, 1136, ResolutionPolicy::NO_BORDER);
		}
	}
	else if (960 == screenSize.width || 960 == screenSize.height) // retina iPhone (4 and 4S)
	{
		resDirOrders.push_back("iphonehd");
		resDirOrders.push_back("iphone");

		if (true == IS_LANDSCAPE)
		{
			glview->setDesignResolutionSize(960, 640, ResolutionPolicy::NO_BORDER);
		}
		else
		{
			glview->setDesignResolutionSize(640, 960, ResolutionPolicy::NO_BORDER);
		}
	}
	else // non retina iPhone and Android devices
	{
		if (1080 < screenSize.width && 1080 < screenSize.height) // android devices that have a high resolution
		{
			resDirOrders.push_back("iphonehd");
			resDirOrders.push_back("iphone");

			if (true == IS_LANDSCAPE)
			{
				glview->setDesignResolutionSize(960, 640, ResolutionPolicy::NO_BORDER);
			}
			else
			{
				glview->setDesignResolutionSize(640, 960, ResolutionPolicy::NO_BORDER);
			}
		}
		else // non retina iPhone and Android devices with lower resolutions
		{
			resDirOrders.push_back("iphone");

			if (true == IS_LANDSCAPE)
			{
				glview->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
			}
			else
			{
				glview->setDesignResolutionSize(320, 480, ResolutionPolicy::NO_BORDER);
			}
		}
	}

#elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
	resDirOrders.push_back("ipad");
	resDirOrders.push_back("iphonehd5");
	resDirOrders.push_back("iphonehd");
	resDirOrders.push_back("iphone");

	if (true == IS_LANDSCAPE)
	{
		glview->setFrameSize(1024, 768);
		glview->setDesignResolutionSize(1024, 768, ResolutionPolicy::NO_BORDER);
	}
	else
	{
		glview->setFrameSize(768, 1024);
		glview->setDesignResolutionSize(768, 1024, ResolutionPolicy::NO_BORDER);
	}
#endif
    
    fileUtils->setSearchPaths(resDirOrders);
    
    // create a scene. it's an autorelease object
    auto scene = SplashScene::createScene();
    
    // run
    director->runWithScene(scene);
    
    return true;
}
Ejemplo n.º 8
0
KDbool AppDelegate::applicationDidFinishLaunching ( KDvoid )
{
	// initialize director
	auto	pDirector = Director::getInstance ( );
	pDirector->setOpenGLView ( EGLView::getInstance ( ) );

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

	auto	tScreenSize = EGLView::getInstance ( )->getFrameSize ( );

	auto	tDesignSize = Size ( 480, 320 );

	auto	pFileUtils = FileUtils::getInstance ( );

	if ( tScreenSize.height > 320 )
	{
		auto	tResourceSize = Size ( 960, 640 );
		std::vector<std::string>	aSearchPaths;
		aSearchPaths.push_back ( "hd" );
		pFileUtils->setSearchPaths ( aSearchPaths );
		pDirector->setContentScaleFactor ( tResourceSize.height / tDesignSize.height );
	}

	EGLView::getInstance ( )->setDesignResolutionSize ( tDesignSize.width, tDesignSize.height, ResolutionPolicy::FIXED_HEIGHT );

	// register lua engine
	LuaEngine*	pEngine = LuaEngine::getInstance ( );
	ScriptEngineManager::getInstance ( )->setScriptEngine ( pEngine );

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID ||CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
	LuaStack*	pStack = pEngine->getLuaStack ( );
	register_assetsmanager_test_sample ( pStack->getLuaState ( ) );
#endif

	std::vector<std::string>	aSearchPaths = pFileUtils->getSearchPaths ( );
	aSearchPaths.insert ( aSearchPaths.begin(), "Images" );
	aSearchPaths.insert ( aSearchPaths.begin(), "cocosbuilderRes" );
	if ( tScreenSize.height > 320 )
	{
		aSearchPaths.insert ( aSearchPaths.begin ( ), "hd/scenetest" );
	}
	else
	{
		aSearchPaths.insert ( aSearchPaths.begin ( ), "scenetest" );
	}

#if CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY
	aSearchPaths.push_back ( "TestCppResources" );
	aSearchPaths.push_back ( "script" );
#endif

	FileUtils::getInstance ( )->setSearchPaths ( aSearchPaths );

	pEngine->executeScriptFile ( "luaScript/controller.lua" );

    return true;
}
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("My Game");
        director->setOpenGLView(glview);
    }
    
    // turn on display FPS
    director->setDisplayStats(false);
    
    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);
    
    // MULTI RESOLUTION SUPPORT FOR V3
    // Credits: http://becomingindiedev.blogspot.com/2014/05/multi-resolution-support-in-ios-with.html
    auto screenSize = glview->getFrameSize();
    
    auto fileUtils = FileUtils::getInstance();
    std::vector<std::string> searchPaths;
    
    if (screenSize.width == 2048 || screenSize.height == 2048)
    {
        glview -> setDesignResolutionSize(1536, 2048, ResolutionPolicy::NO_BORDER);
        searchPaths.push_back("ipadhd");
        searchPaths.push_back("ipadsd");
        searchPaths.push_back("iphone5");
        searchPaths.push_back("iphonehd");
        searchPaths.push_back("iphonesd");
    }
    else if (screenSize.width == 1024 || screenSize.height == 1024)
    {
        glview -> setDesignResolutionSize(768, 1024, ResolutionPolicy::NO_BORDER);
        searchPaths.push_back("ipadsd");
        searchPaths.push_back("iphone5");
        searchPaths.push_back("iphonehd");
        searchPaths.push_back("iphonesd");
        
    }
    else if (screenSize.width == 1136 || screenSize.height == 1136)
    {
        glview -> setDesignResolutionSize(640, 1136, ResolutionPolicy::NO_BORDER);
        searchPaths.push_back("iphone5");
        searchPaths.push_back("iphonehd");
        searchPaths.push_back("iphonesd");
        
    }
    else if (screenSize.width == 960 || screenSize.height == 960)
    {
        glview -> setDesignResolutionSize(640, 960, ResolutionPolicy::NO_BORDER);
        searchPaths.push_back("iphonehd");
        searchPaths.push_back("iphonesd");
    }
    else
    {
        searchPaths.push_back("iphonesd");
        glview -> setDesignResolutionSize(320, 480, ResolutionPolicy::NO_BORDER);
    }
    
    fileUtils->setSearchPaths(searchPaths);
    
    // create a scene. it's an autorelease object
    
    // run
    auto scene = WelcomeScene::createScene();
    director->runWithScene(scene);
    
    return true;
}
Ejemplo n.º 10
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
    Configuration::getInstance()->loadConfigFile("configs/config-example.plist");

    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLView::create("Cpp Tests");
        director->setOpenGLView(glview);
    }

    director->setDisplayStats(true);
    director->setAnimationInterval(1.0 / 60);

    auto screenSize = glview->getFrameSize();

    auto designSize = Size(480, 320);

    auto fileUtils = FileUtils::getInstance();
    std::vector<std::string> searchPaths;
    
    if (screenSize.height > 320)
    {
        auto resourceSize = Size(960, 640);
        searchPaths.push_back("hd");
        searchPaths.push_back("ccs-res/hd");
        searchPaths.push_back("ccs-res/hd/scenetest");
        searchPaths.push_back("ccs-res/hd/scenetest/ArmatureComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/AttributeComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/BackgroundComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/EffectComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/LoadSceneEdtiorFileTest");
        searchPaths.push_back("ccs-res/hd/scenetest/ParticleComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/SpriteComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/TmxMapComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/UIComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/TriggerTest");
        searchPaths.push_back("ccs-res");
        director->setContentScaleFactor(resourceSize.height/designSize.height);
    }
    else
    {
        searchPaths.push_back("ccs-res");
        searchPaths.push_back("ccs-res/scenetest/ArmatureComponentTest");
        searchPaths.push_back("ccs-res/scenetest/AttributeComponentTest");
        searchPaths.push_back("ccs-res/scenetest/BackgroundComponentTest");
        searchPaths.push_back("ccs-res/scenetest/EffectComponentTest");
        searchPaths.push_back("ccs-res/scenetest/LoadSceneEdtiorFileTest");
        searchPaths.push_back("ccs-res/scenetest/ParticleComponentTest");
        searchPaths.push_back("ccs-res/scenetest/SpriteComponentTest");
        searchPaths.push_back("ccs-res/scenetest/TmxMapComponentTest");
        searchPaths.push_back("ccs-res/scenetest/UIComponentTest");
        searchPaths.push_back("ccs-res/scenetest/TriggerTest");
    }
    
    fileUtils->setSearchPaths(searchPaths);

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
    // a bug in DirectX 11 level9-x on the device prevents ResolutionPolicy::NO_BORDER from working correctly
    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL);
#else
    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
#endif

    auto scene = Scene::create();
    auto layer = new TestController();
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
    layer->addConsoleAutoTest();
#endif
    layer->autorelease();
    layer->addConsoleAutoTest();
    scene->addChild(layer);
    director->runWithScene(scene);

    // Enable Remote Console
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
    auto console = director->getConsole();
    console->listenOnTCP(5678);
    Configuration *conf = Configuration::getInstance();
    bool isAutoRun = conf->getValue("cocos2d.x.testcpp.autorun", Value(false)).asBool();
    if(isAutoRun)
    {
        layer->startAutoRun();
    }
#endif
    
    return true;
}
Ejemplo n.º 11
0
bool AppDelegate::applicationDidFinishLaunching()
{
    // As an example, load config file
    // FIXME:: This should be loaded before the Director is initialized,
    // FIXME:: but at this point, the director is already initialized
    Configuration::getInstance()->loadConfigFile("configs/config-example.plist");

    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("Cpp Tests");
        director->setOpenGLView(glview);
    }

    director->setDisplayStats(true);
    director->setAnimationInterval(1.0 / 60);

    auto screenSize = glview->getFrameSize();
    auto designSize = Size(480, 320);

    auto fileUtils = FileUtils::getInstance();
    std::vector<std::string> searchPaths;
    
    if (screenSize.height > 320)
    {
        auto resourceSize = Size(960, 640);
        searchPaths.push_back("hd");
        searchPaths.push_back("ccs-res/hd");
        searchPaths.push_back("ccs-res/hd/scenetest");
        searchPaths.push_back("ccs-res/hd/scenetest/ArmatureComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/AttributeComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/BackgroundComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/EffectComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/LoadSceneEdtiorFileTest");
        searchPaths.push_back("ccs-res/hd/scenetest/ParticleComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/SpriteComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/TmxMapComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/UIComponentTest");
        searchPaths.push_back("ccs-res/hd/scenetest/TriggerTest");
        searchPaths.push_back("ccs-res");
        searchPaths.push_back("Manifests");
        director->setContentScaleFactor(resourceSize.height/designSize.height);
        
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIButton");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UICheckBox");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIImageView");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILabel");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILabelBMFont");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/BackgroundImage");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Color");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Layout");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Gradient_Color");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/Scale9_BackgroundImage");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILayout/LayoutComponent");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UILoadingBar");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIPageView");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIScrollView/Both");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIScrollView/Horizontal");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIScrollView/Vertical");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UISlider");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UITextField");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIWidgetAddNode");
        searchPaths.push_back("ccs-res/hd/cocosui/UIEditorTest/UIListView/New");
        
        searchPaths.push_back("ccs-res/hd/cocosui/CustomTest/CustomWidgetCallbackBindTest");
        searchPaths.push_back("hd/ActionTimeline");
        searchPaths.push_back("ccs-res/hd/armature");
    }
    else
    {
        searchPaths.push_back("ccs-res");
        searchPaths.push_back("ccs-res/scenetest/ArmatureComponentTest");
        searchPaths.push_back("ccs-res/scenetest/AttributeComponentTest");
        searchPaths.push_back("ccs-res/scenetest/BackgroundComponentTest");
        searchPaths.push_back("ccs-res/scenetest/EffectComponentTest");
        searchPaths.push_back("ccs-res/scenetest/LoadSceneEdtiorFileTest");
        searchPaths.push_back("ccs-res/scenetest/ParticleComponentTest");
        searchPaths.push_back("ccs-res/scenetest/SpriteComponentTest");
        searchPaths.push_back("ccs-res/scenetest/TmxMapComponentTest");
        searchPaths.push_back("ccs-res/scenetest/UIComponentTest");
        searchPaths.push_back("ccs-res/scenetest/TriggerTest");
        
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIButton");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UICheckBox");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIImageView");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILabel");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILabelBMFont");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/BackgroundImage");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Color");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Layout");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Gradient_Color");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/Scale9_BackgroundImage");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILayout/LayoutComponent");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UILoadingBar");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIPageView");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIScrollView/Both");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIScrollView/Horizontal");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIScrollView/Vertical");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UISlider");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UITextField");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIWidgetAddNode");
        searchPaths.push_back("ccs-res/cocosui/UIEditorTest/UIListView/New");
        
        searchPaths.push_back("ccs-res/cocosui/CustomTest/CustomWidgetCallbackBindTest");
        searchPaths.push_back("ActionTimeline");
        searchPaths.push_back("ccs-res/armature");
    }
    
    fileUtils->setSearchPaths(searchPaths);

    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL);
    
    // Enable Remote Console
    auto console = director->getConsole();
    console->listenOnTCP(5678);

    _testController = TestController::getInstance();
    
    return true;
}
Ejemplo n.º 12
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLView::create("aplicacion X");
		glview->setFrameSize(480, 800);
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(false);

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


	auto fileUtils = FileUtils::getInstance();
	auto screenSize = glview->getFrameSize();
	std::vector<std::string> resDirOrder;


	// vrificamos los deistintos dispositivos.

	if( 2048 == screenSize.width || 2048 ==screenSize.height )
	{
		resDirOrder.push_back("default");

		glview->setDesignResolutionSize(2048,1536, ResolutionPolicy::NO_BORDER);

	}


	else if(1024 == screenSize.width || 1024 == screenSize.height)
	{
	
		resDirOrder.push_back("default2");

		glview->setDesignResolutionSize(1024, 768, ResolutionPolicy::NO_BORDER);
	}


	else if(1136 == screenSize.width || 1136 == screenSize.height)
	{
	
		resDirOrder.push_back("default");

		glview->setDesignResolutionSize(1136, 640, ResolutionPolicy::NO_BORDER);
	}



		else if(960 == screenSize.width || 960 == screenSize.height)
	{
	
		resDirOrder.push_back("default");

		glview->setDesignResolutionSize(960, 640, ResolutionPolicy::NO_BORDER);
	}


		else
		{
		   
			resDirOrder.push_back("default");

			glview->setDesignResolutionSize(380, 650, ResolutionPolicy::NO_BORDER);
		   
		}

		fileUtils->setSearchPaths(resDirOrder);


    // create a scene. it's an autorelease object
    auto scene = HelloWorld::createScene();

    // run
    director->runWithScene(scene);

    return true;
}
Ejemplo n.º 13
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
        glview = GLViewImpl::createWithRect("helloThesis", Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
        glview = GLViewImpl::create("helloThesis");
#endif
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    //director->setDisplayStats(true);

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

    // Set the design resolution
    glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
    Size frameSize = glview->getFrameSize();
    // if the frame's height is larger than the height of medium size.
    if (frameSize.height > mediumResolutionSize.height)
	{
		GameConfig::scale = MIN(largeResolutionSize.height / designResolutionSize.height, largeResolutionSize.width / designResolutionSize.width);
		director->setContentScaleFactor(GameConfig::scale);
	}
    // if the frame's height is larger than the height of small size.
    else if (frameSize.height > smallResolutionSize.height)
	{
		GameConfig::scale = MIN(mediumResolutionSize.height / designResolutionSize.height, mediumResolutionSize.width / designResolutionSize.width);

        director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
    }
    // if the frame's height is smaller than the height of medium size.
    else
	{
		GameConfig::scale = MIN(smallResolutionSize.height / designResolutionSize.height, smallResolutionSize.width / designResolutionSize.width);

        director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
    }

    register_all_packages();

	auto fileUtils = FileUtils::getInstance();
	std::vector<std::string> searchPaths;

	searchPaths.push_back("language");
	searchPaths.push_back("image/small/background");
	searchPaths.push_back("image");
	searchPaths.push_back("cocosStudio");
	searchPaths.push_back("tiles");
	searchPaths.push_back("Button");

	fileUtils->setSearchPaths(searchPaths);
    // create a scene. it's an autorelease object
    auto scene = MainMenuScene::createScene();
    // run
    director->runWithScene(scene);

    return true;
}
Ejemplo n.º 14
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("My Game");
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    //director->setDisplayStats(true);

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

    //tanzimat e multi resolution
    auto fileUtils = FileUtils::getInstance();
    auto screenSize = glview->getFrameSize();
    std::vector<std::string> resDirOrders;

    //check mikonim ke device che assesti neiaz dareh.
    if(2048 == screenSize.width || 2048 == screenSize.height){
    	resDirOrders.push_back("ipadhd");
    	resDirOrders.push_back("ipad");
    	resDirOrders.push_back("iphonehd5");
    	resDirOrders.push_back("iphonehd");
    	resDirOrders.push_back("iphone");

    	glview->setDesignResolutionSize(2048, 1536, ResolutionPolicy::NO_BORDER);
    }
    else if(1024 == screenSize.width || 1024 == screenSize.height){
    	resDirOrders.push_back("ipad");
    	resDirOrders.push_back("iphonehd5");
    	resDirOrders.push_back("iphonehd");
    	resDirOrders.push_back("iphone");

    	glview->setDesignResolutionSize(1024, 768, ResolutionPolicy::NO_BORDER);
    }
    else if(1136 == screenSize.width || 1136 == screenSize.height){
        	resDirOrders.push_back("iphonehd5");
        	resDirOrders.push_back("iphonehd");
        	resDirOrders.push_back("iphone");

        	glview->setDesignResolutionSize(1136, 640, ResolutionPolicy::NO_BORDER);
    }
    else if(960 == screenSize.width || 960 == screenSize.height){
        	resDirOrders.push_back("iphonehd");
        	resDirOrders.push_back("iphone");

        	glview->setDesignResolutionSize(960, 640, ResolutionPolicy::NO_BORDER);
    }
    else{
    	if(1080 < screenSize.width){
    		resDirOrders.push_back("iphonehd");
    		resDirOrders.push_back("iphone");

    		glview->setDesignResolutionSize(960, 640, ResolutionPolicy::NO_BORDER);
    	}
    	else{
    		resDirOrders.push_back("iphone");

    		glview->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
    	}
    }

    fileUtils->setSearchPaths(resDirOrders);

    // create a scene. it's an autorelease object
    auto scene = MainMenu::createScene();

    // run
    director->runWithScene(scene);

    return true;
}
Ejemplo n.º 15
0
void AppDelegate::initPathsForResolution()
{
	// initialize director
	auto l_director = Director::getInstance();
	auto l_glview = l_director->getOpenGLView();

	if (!l_glview)
	{
		l_glview = GLViewImpl::create("Ludomuse");
		l_director->setOpenGLView(l_glview);
	}

	// turn off display FPS
	l_director->setDisplayStats(false);

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

	// Set the design resolution, refer to this link for more information => http://www.cocos2d-x.org/wiki/Detailed_explanation_of_Cocos2d-x_Multi-resolution_adaptation
	//EXACT_FIT || NO_BORDER || SHOW_ALL
	l_glview->setDesignResolutionSize(s_DesignResolutionSize.width,
			s_DesignResolutionSize.height, ResolutionPolicy::NO_BORDER);

	//get the size of the device's screen
	Size l_frameSize = l_glview->getFrameSize();

	//use to determine in what order we search in the ressources directories
	auto l_fileUtils = FileUtils::getInstance();
	std::vector<std::string> l_resDirOrders;

	// if the frame's height is larger than the height of medium size we want to get large ressources
	if (l_frameSize.height > s_MediumResolutionSize.height)
	{
		//we are going to get ressources in the large ressources directorie then in the  medium and finally in the small
		l_resDirOrders.push_back("LargeResolutionSize");
		l_resDirOrders.push_back("MediumResolutionSize");
		l_resDirOrders.push_back("SmallResolutionSize");
		l_director->setContentScaleFactor(
				MIN(
						s_LargeResolutionSize.height
								/ s_DesignResolutionSize.height,
						s_LargeResolutionSize.width
								/ s_DesignResolutionSize.width));
	}
	// if the frame's height is larger than the height of small size.
	else if (l_frameSize.height > s_SmallResolutionSize.height)
	{
		l_resDirOrders.push_back("MediumResolutionSize");
		l_resDirOrders.push_back("SmallResolutionSize");
		l_director->setContentScaleFactor(
				MIN(
						s_MediumResolutionSize.height
								/ s_DesignResolutionSize.height,
						s_MediumResolutionSize.width
								/ s_DesignResolutionSize.width));
	}
	// if the frame's height is smaller than the height of medium size.
	else
	{
		l_resDirOrders.push_back("SmallResolutionSize");
		l_director->setContentScaleFactor(
				MIN(
						s_SmallResolutionSize.height
								/ s_DesignResolutionSize.height,
						s_SmallResolutionSize.width
								/ s_DesignResolutionSize.width));
	}

	//set the paths
	l_fileUtils->setSearchPaths(l_resDirOrders);
}