bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); Size designResolution = Size(2048, 1536); auto glview = director->getOpenGLView(); if(!glview) { glview = GLViewImpl::create("My Game"); glview->setDesignResolutionSize(designResolution.width, designResolution.height, ResolutionPolicy::SHOW_ALL); director->setOpenGLView(glview); } director->setContentScaleFactor(designResolution.height / glview->getFrameSize().height); // 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); // run by customer GameController GameController::getInstance()->enterStartScene(); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { glview = GLView::create("TileMap Test"); glview->setFrameSize(350,350); 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); // create a scene. it's an autorelease object auto scene = HelloWorld::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("7th_Voice"); director->setOpenGLView(glview); glview->setDesignResolutionSize(1136, 640, ResolutionPolicy::SHOW_ALL); } // 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); // create a scene. it's an autorelease object auto scene = CreditScene::createScene(); // run director->runWithScene(scene); return true; }
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; }
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; }
int SimulatorWin::run() { auto player = player::PlayerWin::create(); INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); parseCocosProjectConfig(_project); // load project config from command line args vector<string> args; for (int i = 0; i < __argc; ++i) { wstring ws(__wargv[i]); string s; s.assign(ws.begin(), ws.end()); args.push_back(s); } _project.parseCommandLine(args); if (_project.getProjectDir().empty()) { if (args.size() == 2) { // for Code IDE before RC2 _project.setProjectDir(args.at(1)); _project.setDebuggerType(kCCRuntimeDebuggerCodeIDE); } } // create the application instance _app = new AppDelegate(); _app->setProjectConfig(_project); // create console window if (_project.isShowConsole()) { AllocConsole(); _hwndConsole = GetConsoleWindow(); if (_hwndConsole != NULL) { ShowWindow(_hwndConsole, SW_SHOW); BringWindowToTop(_hwndConsole); freopen("CONOUT$", "wt", stdout); freopen("CONOUT$", "wt", stderr); HMENU hmenu = GetSystemMenu(_hwndConsole, FALSE); if (hmenu != NULL) { DeleteMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); } } } // log file if (_project.isWriteDebugLogToFile()) { const string debugLogFilePath = _project.getDebugLogFilePath(); _writeDebugLogFile = fopen(debugLogFilePath.c_str(), "w"); if (!_writeDebugLogFile) { CCLOG("Cannot create debug log file %s", debugLogFilePath.c_str()); } } // set environments SetCurrentDirectoryA(_project.getProjectDir().c_str()); FileUtils::getInstance()->setDefaultResourceRootPath(_project.getProjectDir()); FileUtils::getInstance()->setWritablePath(_project.getWritableRealPath().c_str()); // check screen DPI HDC screen = GetDC(0); int dpi = GetDeviceCaps(screen, LOGPIXELSX); ReleaseDC(0, screen); // set scale with DPI // 96 DPI = 100 % scaling // 120 DPI = 125 % scaling // 144 DPI = 150 % scaling // 192 DPI = 200 % scaling // http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#dpi_and_the_desktop_scaling_factor // // enable DPI-Aware with DeclareDPIAware.manifest // http://msdn.microsoft.com/en-us/library/windows/desktop/dn469266%28v=vs.85%29.aspx#declaring_dpi_awareness float screenScale = 1.0f; if (dpi >= 120 && dpi < 144) { screenScale = 1.25f; } else if (dpi >= 144 && dpi < 192) { screenScale = 1.5f; } else if (dpi >= 192) { screenScale = 2.0f; } CCLOG("SCREEN DPI = %d, SCREEN SCALE = %0.2f", dpi, screenScale); // create opengl view Size frameSize = _project.getFrameSize(); float frameScale = 1.0f; if (_project.isRetinaDisplay()) { frameSize.width *= screenScale; frameSize.height *= screenScale; } else { frameScale = screenScale; } const Rect frameRect = Rect(0, 0, frameSize.width, frameSize.height); const bool isResize = _project.isResizeWindow(); std::stringstream title; title << "Cocos Simulator - " << ConfigParser::getInstance()->getInitViewName(); initGLContextAttrs(); auto glview = GLViewImpl::createWithRect(title.str(), frameRect, frameScale); _hwnd = glview->getWin32Window(); DragAcceptFiles(_hwnd, TRUE); //SendMessage(_hwnd, WM_SETICON, ICON_BIG, (LPARAM)icon); //SendMessage(_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon); //FreeResource(icon); auto director = Director::getInstance(); director->setOpenGLView(glview); director->setAnimationInterval(1.0 / 60.0); // set window position if (_project.getProjectDir().length()) { setZoom(_project.getFrameScale()); } Vec2 pos = _project.getWindowOffset(); if (pos.x != 0 && pos.y != 0) { RECT rect; GetWindowRect(_hwnd, &rect); MoveWindow(_hwnd, pos.x, pos.y, rect.right - rect.left, rect.bottom - rect.top, FALSE); } // path for looking Lang file, Studio Default images FileUtils::getInstance()->addSearchPath(getApplicationPath().c_str()); // init player services initServices(); setupUI(); DrawMenuBar(_hwnd); // prepare FileUtils::getInstance()->setPopupNotify(false); _project.dump(); auto app = Application::getInstance(); g_oldWindowProc = (WNDPROC)SetWindowLong(_hwnd, GWL_WNDPROC, (LONG)SimulatorWin::windowProc); // update window size RECT rect; GetWindowRect(_hwnd, &rect); MoveWindow(_hwnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top + GetSystemMetrics(SM_CYMENU), FALSE); // startup message loop return app->run(); }
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("hw9", Rect(0, 0, designResolutionSize.width, designResolutionSize.height)); #else glview = GLViewImpl::create("hw9"); #endif 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); // Set the design resolution glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::EXACT_FIT); 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)); } register_all_packages(); // load game resource SpriteFrameCache::getInstance()->addSpriteFramesWithFile("general-sheet.plist"); char totalFrames = 3; char frameName[20]; Animation* legAnimation = Animation::create(); for (int i = 0; i < totalFrames; i++) { sprintf(frameName, "miner-leg-%d.png", i); legAnimation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(frameName)); } legAnimation->setDelayPerUnit(0.1); AnimationCache::getInstance()->addAnimation(legAnimation, "legAnimation"); Animation* caveAnimation = Animation::create(); for (int i = 0; i < totalFrames; i++) { sprintf(frameName, "cave-%d.png", i); caveAnimation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(frameName)); } caveAnimation->setDelayPerUnit(0.1); AnimationCache::getInstance()->addAnimation(caveAnimation, "caveAnimation"); auto scene = MenuSence::createScene(); // run director->runWithScene(scene); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if (!glview) { glview = GLView::createWithRect("Flappy Ponta", cocos2d::Rect(0, 0, 480, 640), 1); director->setOpenGLView(glview); } glview->setDesignResolutionSize(AppDelegate::BASE_WIDTH, AppDelegate::BASE_HEIGHT, ResolutionPolicy::NO_BORDER); cocos2d::Size frameSize = glview->getFrameSize(); cocos2d::log("frame size %f, %f", frameSize.width, frameSize.height); std::vector<std::string> searchPath; if (frameSize.height >= 1920) { this->resolutionScale = AppDelegate::SCALE_XXH_RES; searchPath.push_back("gfx/xxh_res"); } else if (frameSize.height >= 1280) { this->resolutionScale = AppDelegate::SCALE_XH_RES; searchPath.push_back("gfx/xh_res"); } else if (frameSize.height >= 960) { this->resolutionScale = AppDelegate::SCALE_H_RES; searchPath.push_back("gfx/h_res"); } else if (frameSize.height >= 640) { this->resolutionScale = AppDelegate::SCALE_M_RES; searchPath.push_back("gfx/m_res"); } else { this->resolutionScale = AppDelegate::SCALE_L_RES; searchPath.push_back("gfx/l_res"); } searchPath.push_back("gfx/all_res"); searchPath.push_back("sfx"); FileUtils::getInstance()->setSearchPaths(searchPath); cocos2d::log("resolution scale %f, %f", resolutionScale, (AppDelegate::BASE_WIDTH * this->resolutionScale) / AppDelegate::BASE_WIDTH); director->setContentScaleFactor(this->resolutionScale); // 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); pluginAnalytics = dynamic_cast<cocos2d::plugin::ProtocolAnalytics*> (cocos2d::plugin::PluginManager::getInstance()->loadPlugin("GoogleAnalytics")); pluginAnalytics->setDebugMode(false); pluginAnalytics->startSession("UA-55456421-4"); pluginAnalytics->setCaptureUncaughtException(true); pluginAnalytics->setSessionContinueMillis(300); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) const char *pluginName = "AppleGameCenter"; #else const char *pluginName = "GpsGames"; #endif pluginGameServices = dynamic_cast<cocos2d::plugin::ProtocolGameServices*> (cocos2d::plugin::PluginManager::getInstance()->loadPlugin(pluginName)); pluginGameServices->setDebugMode(false); pluginGameServices->startSession(); auto scene = LoadingScene::create(); director->runWithScene(scene); return true; }
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; }
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; }
bool AppDelegate::applicationDidFinishLaunching() { // add search path std::vector<std::string> searchPath; searchPath.push_back("dat"); searchPath.push_back("ipad"); // TODO FileUtils::getInstance()->setSearchPaths(searchPath); // initialize director auto director = Director::getInstance(); auto eglView = EGLView::getInstance(); director->setOpenGLView(eglView); // 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); // load dictionary cocos2d::LanguageType currentLanguageType = cocos2d::Application::getInstance()->getCurrentLanguage(); std::string filename; if ( currentLanguageType == cocos2d::LanguageType::JAPANESE ) { filename = "dic.ja"; } else { filename = "dic.en"; } Global::init(filename); /* int DESIGN_WIDTH = 640.0f; int DESIGN_HEIGHT = 960.0f; Global::getInstance()->BLOCK_WIDTH = 80; float PLAYAREA_X = 40.0f; float PLAYAREA_Y = 80.0f; */ int DESIGN_WIDTH = 1536.0f; int DESIGN_HEIGHT = 2048.0f; Global::getInstance()->BLOCK_WIDTH = 170; float PLAYAREA_X = 171.0f; float PLAYAREA_Y = 171.0f; Global::getInstance()->WINDOW_WIDTH = DESIGN_WIDTH; Global::getInstance()->WINDOW_HEIGHT = DESIGN_HEIGHT; auto screenSize = EGLView::getInstance()->getFrameSize(); auto designSize = Size(DESIGN_WIDTH, DESIGN_HEIGHT); Size winSize = director->getWinSize(); if (winSize.width > winSize.height * 1.5) { designSize.width = DESIGN_HEIGHT * winSize.width / winSize.height; } else { designSize.height = DESIGN_WIDTH * winSize.height / winSize.width; } Global::getInstance()->designWidth = designSize.width; Global::getInstance()->designHeight = designSize.height; Global::getInstance()->paddingX = (designSize.width - DESIGN_WIDTH) / 2; Global::getInstance()->paddingY = (designSize.height - DESIGN_HEIGHT) / 2; Global::getInstance()->playArea = cocos2d::Rect(PLAYAREA_X + Global::getInstance()->paddingX, PLAYAREA_Y + Global::getInstance()->paddingY, Global::FIELD_COL_NUM * Global::getInstance()->BLOCK_WIDTH, Global::FIELD_ROW_NUM * Global::getInstance()->BLOCK_WIDTH); cocos2d::log("W_SIZE %f:%f %f:%f %f:%f", winSize.width, winSize.height, designSize.width, designSize.height, Global::getInstance()->paddingX, Global::getInstance()->paddingY); eglView->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL ); // create a scene. it's an autorelease object //auto scene = Main::createScene(); auto scene = Title::createScene(); // run director->runWithScene(scene); return true; }
//初始化方法 bool AppDelegate::applicationDidFinishLaunching() { //获取导演 auto director = Director::getInstance(); auto glview = director->getOpenGLView(); //若不存在glview则重新创建 if(!glview) { glview = GLView::create("Test Cpp"); } //设置绘制用GLView director->setOpenGLView(glview); //设置目标分辨率,别的分辨率的屏幕将自动上下或左右留白进行多分辨率自适应 glview->setDesignResolutionSize(960,540,ResolutionPolicy::SHOW_ALL); //设置为显示FPS等信息 director->setDisplayStats(false); //系统模拟时间间隔 director->setAnimationInterval(1.0 / 60); //创建欢迎场景 Scene *scene = TankSceneManager::WelcomeCreate(); //跌换到欢迎场景显示 director->runWithScene(scene); //加载背景音乐 CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic ( (SOUND_PATH+std::string("background.mp3")).c_str() ); //加载吃到奖励的音效 CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect ( (SOUND_PATH+std::string("eatprops.wav")).c_str() ); //加载爆炸音效 CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect ( (SOUND_PATH+std::string("grenada.ogg")).c_str() ); //加载爆炸音效 CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect ( (SOUND_PATH+std::string("lose.mp3")).c_str() ); //加载爆炸音效 CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect ( (SOUND_PATH+std::string("rocket_shoot2.ogg")).c_str() ); //加载爆炸音效 CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect ( (SOUND_PATH+std::string("select.wav")).c_str() ); Constant::musicFlag=UserDefault::getInstance()->getBoolForKey("music", true); Constant::effectFlag=UserDefault::getInstance()->getBoolForKey("effect", true); Constant::playMusic(); 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(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; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { glview = GLViewImpl::create("My Game"); director->setOpenGLView(glview); } // Set the design resolution Size winSize = director->getWinSize(); float ratio = winSize.width/winSize.height; scaleFactory = 1; if (ratio > 1.73) {//1.78 if(winSize.width > 1600){ glview->setDesignResolutionSize(designResolutionSizeA_HD.width, designResolutionSizeA_HD.height, ResolutionPolicy::EXACT_FIT); scaleFactory = 1.0; FileUtils::getInstance()->addSearchPath("resHD"); }else{ glview->setDesignResolutionSize(designResolutionSizeA.width, designResolutionSizeA.height, ResolutionPolicy::EXACT_FIT); scaleFactory = 1280.0/2208.0; FileUtils::getInstance()->addSearchPath("res"); } }else if (ratio > 1.63){//1.67 glview->setDesignResolutionSize(designResolutionSizeB.width, designResolutionSizeB.height, ResolutionPolicy::EXACT_FIT); scaleFactory = 1280.0/2208.0; FileUtils::getInstance()->addSearchPath("res"); }else if (ratio > 1.55){ glview->setDesignResolutionSize(designResolutionSizeC.width, designResolutionSizeC.height, ResolutionPolicy::EXACT_FIT); scaleFactory = 1280.0/2208.0; FileUtils::getInstance()->addSearchPath("res"); }else if (ratio > 1.45){ glview->setDesignResolutionSize(designResolutionSizeD.width, designResolutionSizeD.height, ResolutionPolicy::EXACT_FIT); scaleFactory = 1280.0/2208.0; FileUtils::getInstance()->addSearchPath("res"); }else{//ipad if(winSize.width > 1024){ glview->setDesignResolutionSize(designResolutionSizeE_HD.width, designResolutionSizeE_HD.height, ResolutionPolicy::EXACT_FIT); scaleFactory = 2048.0/2208.0; FileUtils::getInstance()->addSearchPath("resIpadHD"); }else{ glview->setDesignResolutionSize(designResolutionSizeE.width, designResolutionSizeE.height, ResolutionPolicy::EXACT_FIT); scaleFactory = 1024.0/2208.0; FileUtils::getInstance()->addSearchPath("resIpad"); } } //glview->setContentScaleFactor(scaleFactory); // 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); register_all_packages(); // create a scene. it's an autorelease object auto scene = LoadScene::createScene(); // run director->runWithScene(scene); return true; }
bool AppDelegate::applicationDidFinishLaunching() { srand ((unsigned)time(nullptr)); // initialize director auto director = cocos2d::Director::getInstance(); auto glview = director->getOpenGLView(); if (!glview) { glview = cocos2d::GLViewImpl::createWithRect(std::string("divider"), cocos2d::Rect(0, 0, 540, 960), 1.0f); director->setOpenGLView(glview); } glview->setDesignResolutionSize(AppDelegate::BASE_WIDTH, AppDelegate::BASE_HEIGHT, ResolutionPolicy::NO_BORDER, ResolutionGravity::CENTER); cocos2d::Size frameSize = glview->getFrameSize(); cocos2d::log("frame size %f, %f", frameSize.width, frameSize.height); std::vector<std::string> searchPath; if (frameSize.height >= 1920 * 0.9f) { this->resolutionScale = AppDelegate::SCALE_XXH_RES; searchPath.push_back("gfx/xxh_res"); } else if (frameSize.height >= 1280 * 0.9f) { this->resolutionScale = AppDelegate::SCALE_XH_RES; searchPath.push_back("gfx/xh_res"); } else if (frameSize.height >= 960 * 0.9f) { this->resolutionScale = AppDelegate::SCALE_H_RES; searchPath.push_back("gfx/h_res"); } else if (frameSize.height >= 640 * 0.9f) { this->resolutionScale = AppDelegate::SCALE_M_RES; searchPath.push_back("gfx/m_res"); } else { this->resolutionScale = AppDelegate::SCALE_L_RES; searchPath.push_back("gfx/l_res"); } searchPath.push_back("gfx/all_res"); searchPath.push_back("sfx"); cocos2d::FileUtils::getInstance()->setSearchPaths(searchPath); cocos2d::log("resolution scale %f, %f", resolutionScale, (AppDelegate::BASE_WIDTH * this->resolutionScale) / AppDelegate::BASE_WIDTH); director->setContentScaleFactor(this->resolutionScale); // 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); pluginAnalytics = dynamic_cast<cocos2d::plugin::ProtocolAnalytics*> (cocos2d::plugin::PluginManager::getInstance()->loadPlugin("GoogleAnalytics")); pluginAnalytics->setDebugMode(true); pluginAnalytics->startSession("UA-3393187-14"); pluginAnalytics->setCaptureUncaughtException(true); pluginAnalytics->setSessionContinueMillis(300); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) const char *gsPluginName = "AppleGameCenter"; #else const char *gsPluginName = "GpsGames"; #endif pluginGameServices = dynamic_cast<cocos2d::plugin::ProtocolGameServices*> (cocos2d::plugin::PluginManager::getInstance()->loadPlugin(gsPluginName)); pluginGameServices->setDebugMode(true); /* #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) const char *iapPluginName = "IAPAppleStore"; #else const char *iapPluginName = "IAPGooglePlay"; #endif pluginIAP = dynamic_cast<cocos2d::plugin::ProtocolIAP*> (cocos2d::plugin::PluginManager::getInstance()->loadPlugin(iapPluginName)); cocos2d::plugin::TIAPDeveloperInfo devInfo; #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) devInfo.insert(std::pair<std::string, std::string>("GooglePlayAppKey", "")); #endif // pluginIAP->setInventoryCallback(CC_CALLBACK_1(AppDelegate::IAPInventoryCallback, this)); pluginIAP->configDeveloperInfo(devInfo); pluginIAP->setDebugMode(true); */ cocos2d::UserDefault* ud = cocos2d::UserDefault::getInstance(); showAds = !ud->getBoolForKey("remove_ads", false); // create a scene. it's an autorelease object auto scene = IntroScene::create(); // run director->runWithScene(scene); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { glview = GLViewImpl::create("Richer"); director->setOpenGLView(glview); } glview->setDesignResolutionSize(800, 480, ResolutionPolicy::EXACT_FIT); // 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); // create a scene. it's an autorelease object auto scene = HelloWorld::createScene(); // run director->runWithScene(scene); //初始化背景音乐 SimpleAudioEngine::getInstance()->preloadBackgroundMusic(BG01_MP3); SimpleAudioEngine::getInstance()->preloadBackgroundMusic(BG02_MP3); SimpleAudioEngine::getInstance()->preloadBackgroundMusic(BG03_MP3); SimpleAudioEngine::getInstance()->preloadBackgroundMusic(PARTICLE_EFFECT); SimpleAudioEngine::getInstance()->preloadBackgroundMusic(WALK_MP3); //初始化音效 SimpleAudioEngine::getInstance()->preloadEffect(BUTTON_CLICK); SimpleAudioEngine::getInstance()->preloadEffect(BUTTON_CLICK_01); SimpleAudioEngine::getInstance()->preloadEffect(STORM_EFFECT); SimpleAudioEngine::getInstance()->preloadEffect(BLOCK_THE_WAY); SimpleAudioEngine::getInstance()->preloadEffect(STORM_SPEAKING); //交过路费声音 SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00435); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00461); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00475); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_01060); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_01062); //抢夺别人地块 SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00429); //房屋被抢夺 SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00430); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00464); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00469); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00470); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00476); //房屋被摧毁 SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00462); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00463); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00466); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00468); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00474); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_01061); //摧毁别人房屋 SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00433); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00437); //收取过路费 SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00453); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_01059); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_01057); //升级房子 SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_01051); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_01066); //买地 SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00458); SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_01067); //对方被罚收税 SimpleAudioEngine::getInstance()->preloadEffect(P1_Speaking_00452); //交过路费声音 SimpleAudioEngine::getInstance()->preloadEffect(P2_SPEAKING01); SimpleAudioEngine::getInstance()->preloadEffect(P2_QISIWOLE); SimpleAudioEngine::getInstance()->preloadEffect(P2_XINHAOKONGA); SimpleAudioEngine::getInstance()->preloadEffect(P2_BUHUIBA); SimpleAudioEngine::getInstance()->preloadEffect(P2_PAYHIGH); SimpleAudioEngine::getInstance()->preloadEffect(P2_QIANGQIANA); SimpleAudioEngine::getInstance()->preloadEffect(P2_HEBAOCHUXIE); //抢夺别人地块 SimpleAudioEngine::getInstance()->preloadEffect(P2_BIEGUAIWO); SimpleAudioEngine::getInstance()->preloadEffect(P2_SPEAKING02); SimpleAudioEngine::getInstance()->preloadEffect(P2_TIGER); SimpleAudioEngine::getInstance()->preloadEffect(P2_NIDEJIUSHODE); //房屋被抢夺 SimpleAudioEngine::getInstance()->preloadEffect(P2_ZHENMIANMU); SimpleAudioEngine::getInstance()->preloadEffect(P2_WODEDIQI); SimpleAudioEngine::getInstance()->preloadEffect(P2_HAOQIFU); SimpleAudioEngine::getInstance()->preloadEffect(P2_WANGFA); //摧毁别人房屋 SimpleAudioEngine::getInstance()->preloadEffect(P2_NIGAIWOCHAI); SimpleAudioEngine::getInstance()->preloadEffect(P2_KANWODE); SimpleAudioEngine::getInstance()->preloadEffect(P2_HAIRENLE); SimpleAudioEngine::getInstance()->preloadEffect(P2_BAOCHOU); //房屋被摧毁 SimpleAudioEngine::getInstance()->preloadEffect(P2_WODEYANGFANG); SimpleAudioEngine::getInstance()->preloadEffect(P2_QIFURENJIA); SimpleAudioEngine::getInstance()->preloadEffect(P2_SHAQIANDAO); SimpleAudioEngine::getInstance()->preloadEffect(P2_LIANXIANGXIYU); SimpleAudioEngine::getInstance()->preloadEffect(P2_HAOJIUGAIHAO); //收取过路费 SimpleAudioEngine::getInstance()->preloadEffect(P2_RENBUWEIJI); SimpleAudioEngine::getInstance()->preloadEffect(P2_XIAOQI); SimpleAudioEngine::getInstance()->preloadEffect(P2_RONGXING); SimpleAudioEngine::getInstance()->preloadEffect(P2_MANYI); SimpleAudioEngine::getInstance()->preloadEffect(P2_XIAOFUPO); SimpleAudioEngine::getInstance()->preloadEffect(P2_DUOGEI); //升级房子 SimpleAudioEngine::getInstance()->preloadEffect(P2_HIGHER); SimpleAudioEngine::getInstance()->preloadEffect(P2_WANZHANGGAOLOU); //买地 SimpleAudioEngine::getInstance()->preloadEffect(P2_BUYIT); SimpleAudioEngine::getInstance()->preloadEffect(P2_HAODEKAISHI); SimpleAudioEngine::getInstance()->preloadEffect(P2_RANGNIZHU); SimpleAudioEngine::getInstance()->preloadEffect(P2_MAIWOBA); //对方被罚收税 SimpleAudioEngine::getInstance()->preloadEffect(P2_TOUSHUI); SimpleAudioEngine::getInstance()->preloadEffect(P2_FALVZHICAI); SimpleAudioEngine::getInstance()->preloadEffect(P2_GUOKU); SimpleAudioEngine::getInstance()->preloadEffect(P2_NASHUI); return true; }
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; }
bool AppDelegate::applicationDidFinishLaunching() { std::vector<std::string> resources_List { "../Resources/battle", "../Resources/fonts", "../Resources/image", "../Resources/mp3", "../Resources/Sprite3DTest", "../Resources/Particle3D/materials", "../Resources/Particle3D/scripts", "../Resources/Particle3D/textures", }; for (int i = 0; i < resources_List.size(); i++) { cocos2d::FileUtils::getInstance()->addSearchPath(std::string(resources_List[i].c_str())); //CCLOG("%s", resources_List[i].c_str()); } auto director = cocos2d::Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { glview = cocos2d::GLViewImpl::create("Mock"); 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(); //get SearchPath auto fileUtils = cocos2d::FileUtils::getInstance()->getSearchPaths(); std::vector<std::string>searchPaths; if (screenSize.width == 2048 || screenSize.height == 2048) { glview -> setDesignResolutionSize(2048, 1536, ResolutionPolicy::EXACT_FIT); searchPaths.push_back("hd"); searchPaths.push_back("sd"); } else if(screenSize.width == 1024 || screenSize.height == 1024) { glview -> setDesignResolutionSize(1024, 768, ResolutionPolicy::EXACT_FIT); searchPaths.push_back("hd"); searchPaths.push_back("sd"); } else if(screenSize.width == 1136 || screenSize.height == 1136) { glview -> setDesignResolutionSize(1136, 640, ResolutionPolicy::EXACT_FIT); searchPaths.push_back("hd"); searchPaths.push_back("sd"); } else if(screenSize.width == 960 || screenSize.height == 960) { glview -> setDesignResolutionSize(960, 640, ResolutionPolicy::EXACT_FIT); searchPaths.push_back("hd"); searchPaths.push_back("sd"); } else { //glview->setDesignResolutionSize(320, 480, ResolutionPolicy::EXACT_FIT); } glview -> setDesignResolutionSize(1136, 640, ResolutionPolicy::EXACT_FIT); searchPaths.push_back("data"); //挿入 std::vector<std::string>::iterator it = searchPaths.begin(); searchPaths.insert(it, cocos2d::FileUtils::getInstance()->getWritablePath()); cocos2d::FileUtils::getInstance()->setSearchPaths(searchPaths); // create a scene. it's an autorelease object auto scene = TopScene::createScene(); // run director->runWithScene(scene); 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; }
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(false); // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); //屏幕大小 //auto screenSize=glview->getFrameSize(); glview->setFrameSize(320,480); auto screenSize=Size(640,960); //设计分辨率 auto designSize=Size(320,480); //资源大小 auto resourceSize=Size(640,960); std::vector<std::string> SearchPaths; /*if(screenSize.height>960) { designSize=Size(320,568); resourceSize=Size(640,1136); SearchPaths.push_back("hd5"); //////////////////////// }*/ if(screenSize.height>960) { designSize=Size(320,568); SearchPaths.push_back("hd"); } else if(screenSize.height>480) { resourceSize=Size(640,960); SearchPaths.push_back("hd"); } else { SearchPaths.push_back("sd"); } director->setContentScaleFactor(resourceSize.width/designSize.width); FileUtils::getInstance()->setSearchPaths(SearchPaths); glview->setDesignResolutionSize(designSize.width,designSize.height,ResolutionPolicy::FIXED_WIDTH); // create a scene. it's an autorelease object auto scene = HelloWorld::createScene(); // run director->runWithScene(scene); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) glview = GLViewImpl::createWithRect( "Framework", Rect( 0, 0, designResolutionSize.width, designResolutionSize.height ) ); #else glview = GLViewImpl::create("My Game"); #endif director->setOpenGLView(glview); } #ifdef FORCE_DEBUG // turn on display FPS director->setDisplayStats(true); #endif // 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)); } register_all_packages(); // create a scene. it's an autorelease object auto scene = TitleScene::create(); // run SceneManager::getInstance()->replaceScene( scene ); //director->runWithScene(scene); //data init #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) sql_manager::set_db(""); #elif (CC_TARGET_PLATFORM ==CC_PLATFORM_WIN32) sql_manager::set_db((const char*)"./db/rayjack"); accessor::init(); // CCLOG(""); #endif 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(true); // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); Size size=glview->getFrameSize(); Size designSize(1136,640); // float scaleX=size.width/designSize.width; float scaleY=size.height/designSize.height; // glview->setDesignResolutionSize(size.width/scaleY,designSize.height,ResolutionPolicy::SHOW_ALL); glview->setDesignResolutionSize(1136, 640, ResolutionPolicy::FIXED_HEIGHT); // glview->setDesignResolutionSize(1136.0, 640.0, ResolutionPolicy::FIXED_WIDTH); std::vector<std::string>searchPath=FileUtils::getInstance()->getSearchPaths(); searchPath.push_back("/"); searchPath.push_back("bg"); searchPath.push_back("bone"); searchPath.push_back("bone/juqi_1"); searchPath.push_back("bone/juqi_2"); searchPath.push_back("bone/juqi_3"); searchPath.push_back("common"); searchPath.push_back("data"); searchPath.push_back("Default"); searchPath.push_back("effect"); searchPath.push_back("fight"); searchPath.push_back("fonts"); searchPath.push_back("icon"); searchPath.push_back("icon/portrait"); searchPath.push_back("luoLi"); searchPath.push_back("particle"); searchPath.push_back("tmx"); searchPath.push_back("res"); searchPath.push_back("res/Default"); FileUtils::getInstance()->setSearchPaths(searchPath); // director->setContentScaleFactor(640.0/320.0); std::string pathToSave = FileUtils::getInstance()->getWritablePath(); pathToSave += "tmpdir"; std::vector<std::string> searchPaths = FileUtils::getInstance()->getSearchPaths(); std::vector<std::string>::iterator iter = searchPaths.begin(); searchPaths.insert(iter, pathToSave); FileUtils::getInstance()->setSearchPaths(searchPaths); // create a scene. it's an autorelease object // auto scene = TestScene2::createScene(); auto scene = LoginScene::createScene(); // auto scene = Update::createScene(); // auto scene=TestShadeScene::createScene(); // run // director->runWithScene(scene); // // Manager::getInstance()->scene=scene; Manager::getInstance()->initCommonRes(); Manager::getInstance()->switchScence(scene); auto listener = EventListenerKeyboard::create(); listener->onKeyReleased =[&](EventKeyboard::KeyCode keyCode, Event* event) { if(keyCode == EventKeyboard::KeyCode::KEY_BACKSPACE) { Director::getInstance()->end(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) exit(0); #endif } }; Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(listener, -1); return true; }
bool AppDelegate::applicationDidFinishLaunching() { #if COCOS2D_DEBUG #endif cocos2d::log("Hello world! CCLog! = %d", std::this_thread::get_id()); CCLOG("Hello world! CCLOG"); // 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("u2", cocos2d::Rect(0, 0, winResolutionSize.width, winResolutionSize.height)); #else glview = GLViewImpl::create("u2"); #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); cocos2d::Size frameSize = glview->getFrameSize(); //director->setContentScaleFactor(2.0f); /* // 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)); } */ register_all_packages(); FileUtils::getInstance()->addSearchPath(FileUtils::getInstance()->getWritablePath()); cocos2d::FileUtils::getInstance()->addSearchPath("res"); cocos2d::FileUtils::getInstance()->addSearchPath("res/entities"); cocos2d::FileUtils::getInstance()->addSearchPath("res/ui/plist"); cocos2d::FileUtils::getInstance()->addSearchPath("res/ui/application"); cocos2d::FileUtils::getInstance()->addSearchPath("res/ui/joystick"); cocos2d::FileUtils::getInstance()->addSearchPath("res/ui/cg"); cocos2d::FileUtils::getInstance()->addSearchPath("res/ui/ui_info"); { //------------------------------- init u2 ---------------------------------------- m_pRoot = U2_NEW GameRoot; m_pRoot->enter(); } { //------------------------------- Test Thread ---------------------------------------- /* // Create a thread pool TaskGroup group(1); // Run a function in the thread pool for (int i = 0; i < 1; ++i) { group.run([=] { //cocos2d::log("Hello world! run = %d, %d", i, std::this_thread::get_id()); //CCLOG("Hello world! run = %d, %d", i, std::this_thread::get_id()); u2::LogManager::getSingleton().stream(u2::LML_NORMAL) << "Hello world! run = " << i << ", " << std::this_thread::get_id() << "\n"; }); //pool.run([i] { std::cout << "Hello world! = " << i << std::endl; }); } // Wait for all queued functions to finish and the pool to become empty group.wait(); u2::LogManager::getSingleton().stream(u2::LML_NORMAL) << "Hello world! main = " << std::this_thread::get_id() << "\n"; cocos2d::log("Hello world! Thread over!"); */ } { //------------------------------- Test ObjectCollection ---------------------------------------- /* ObjectCollection<u2::Context> collect; collect.createObject(OT_Context, "aaa"); collect.createObject(OT_Context, "ddd"); collect.createObject(OT_Context, "eee"); collect.createObject(OT_Context, "www"); collect.createObject(OT_Context, "ccc"); collect.createObject(OT_Context, "www"); ObjectCollection<u2::Context>::ObjectMapIterator objIt = collect.retrieveAllObjectsByName("www"); while (objIt.hasMoreElements()) { u2::Context* pContext = dynamic_cast<u2::Context*>(objIt.getNext()); CCLOG("=========Name, %s, %s", pContext->getName().c_str(), pContext->getGuid().c_str()); } ObjectCollection<u2::Context>::ObjectMapIterator objIt2 = collect.retrieveAllObjectsByTN(OT_Context, "www"); while (objIt2.hasMoreElements()) { u2::Context* pContext = dynamic_cast<u2::Context*>(objIt2.getNext()); CCLOG("=========TN, %s, %s", pContext->getName().c_str(), pContext->getGuid().c_str()); } ObjectCollection<u2::Context>::ObjectMapIterator objIt3 = collect.retrieveAllObjectsByType(OT_Context); while (objIt3.hasMoreElements()) { u2::Context* pContext = dynamic_cast<u2::Context*>(objIt3.getNext()); CCLOG("=========Type, %s, %s", pContext->getName().c_str(), pContext->getGuid().c_str()); } u2::Context* pContext = collect.retrieveObjectByGuid("class u2::Context6"); CCLOG("=========Guid, %s, %s", pContext->getName().c_str(), pContext->getGuid().c_str()); */ } { //------------------------------- Test Stream ---------------------------------------- /* FilterOutQueue<DataFilterOutStream> out; out.push<FileOutStream>("aaa", "D://aaa.txt", std::ios_base::out); out.push<DataFilterOutStream>("bbb"); out->writeInt32(100); out->close(); FilterInQueue<DataFilterInStream> in; in.push<FileInStream>("aaa", "D://aaa.txt", std::ios_base::in); in.push<DataFilterInStream>("bbb"); u2int32 n = in->readInt32(); OutStreamQueue<DataFilterOutStream> out; out.push<FileHandleOutStream>("aaa", "D://aaa.txt", "wb"); out.push<DataFilterOutStream>("bbb"); out->writeInt64(150); out->close(); InStreamQueue<DataFilterInStream> in; in.push<FileHandleInStream>("aaa", "D://aaa.txt", "rb"); in.push<DataFilterInStream>("bbb"); u2int64 n = in->readInt64(); PipedInStream* pPipeIn = new PipedInStream; PipedOutStream* pPipeOut = new PipedOutStream; pPipeIn->connect(pPipeOut); TestInThread* pInTread = new TestInThread(pPipeIn); TestOutThread* pOutTread = new TestOutThread(pPipeOut); TaskGroup group(2); group.run(pInTread); group.run(pOutTread); group.wait(); int bbb = 0; */ } return true; }
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; }
bool AppDelegate::applicationDidFinishLaunching() { guanKa =1; // background music BACKMUSIC = JNIUtil::getBool("backMusic",true,classPath.c_str()); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("sound/background.mp3"); if (BACKMUSIC){ CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("sound/background.mp3",true); } CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("sound/fire.mp3"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("sound/failure.mp3"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("sound/mainback.mp3"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("sound/victory.mp3"); // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { glview = GLView::create("My Game"); director->setOpenGLView(glview); } // Set the design resolution #if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionShowAll); #else /*glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder);*/ glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionShowAll); #endif Size frameSize = glview->getFrameSize(); std::vector<std::string,std::allocator<std::string>> searchPath; // In this demo, we select resource according to the frame's height. // If the resource size is different from design resolution size, you need to set contentScaleFactor. // We use the ratio of resource's height to the height of design resolution, // this can make sure that the resource's height could fit for the height of design resolution. // if the frame's height is larger than the height of medium resource size, select large resource. if (frameSize.height > mediumResource.size.height) { searchPath.push_back(largeResource.directory); director->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width)); } // if the frame's height is larger than the height of small resource size, select medium resource. else if (frameSize.height > smallResource.size.height) { searchPath.push_back(mediumResource.directory); director->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width)); } // if the frame's height is smaller than the height of medium resource size, select small resource. else { searchPath.push_back(smallResource.directory); director->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width)); } // manual add for show all director->setContentScaleFactor(1.0); // set searching path FileUtils::sharedFileUtils()->setSearchPaths(searchPath); // 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); // create a scene. it's an autorelease object auto scene = BanQiuSceneManager::createScene(); // run director->runWithScene(scene); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { #if(CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) glview = cocos2d::GLViewImpl::create("CocosProtobuf"); #else glview = cocos2d::GLViewImpl::createWithRect("CocosProtobuf", Rect(0,0,960,640)); #endif director->setOpenGLView(glview); } // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); ScriptingCore* sc = ScriptingCore::getInstance(); sc->addRegisterCallback(register_all_cocos2dx); sc->addRegisterCallback(register_cocos2dx_js_core); sc->start(); sc->runScript("script/jsb_boot.js"); ScriptEngineProtocol *engine = ScriptingCore::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); ScriptingCore::getInstance()->runScript("main.js"); // test send protobuf message from C++ JSObject* pGlobalObject = ScriptingCore::getInstance()->getGlobalObject(); JSContext* pGlobalContext = ScriptingCore::getInstance()->getGlobalContext(); // Create a GameInfo object first game::info::GameInfo gameInfo; // add RoleInfo object to repeated field game::info::RoleInfo *pRoleInfo1 = gameInfo.add_roleinfo(); pRoleInfo1->set_name("cpp_name1"); pRoleInfo1->set_type(game::enumeration::FIGHTER); // add another RoleInfo object to repeated field game::info::RoleInfo *pRoleInfo2 = gameInfo.add_roleinfo(); pRoleInfo2->set_name("cpp_name2"); pRoleInfo2->set_type(game::enumeration::BOWMAN); // add ItemInfo object to repeated field game::info::ItemInfo *pItemInfo1 = gameInfo.add_iteminfo(); pItemInfo1->set_name("cpp_item1"); pItemInfo1->set_price(100); // add another ItemInfo object to repeated field game::info::ItemInfo *pItemInfo2 = gameInfo.add_iteminfo(); pItemInfo2->set_name("cpp_item2"); pItemInfo2->set_price(200); std::string gameInfoString; gameInfo.SerializeToString(&gameInfoString); // need this before JS_NewArrayBuffer JSAutoCompartment ac(pGlobalContext, pGlobalObject); int length = gameInfoString.length(); JSObject* pMessageJSObject = JS_NewArrayBuffer(pGlobalContext, length); uint8_t* pMessageData = JS_GetArrayBufferData(pMessageJSObject); memcpy((void*)pMessageData, (const void*)gameInfoString.c_str(), gameInfoString.length()); JS::RootedValue ret(pGlobalContext); jsval arg = OBJECT_TO_JSVAL(pMessageJSObject); ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(pGlobalObject), "test_protobuf", 1, &arg, &ret); // game::info::GameInfo* pGameInfo = new game::info::GameInfo; JSObject* pRetJSObject = ret.toObjectOrNull(); if(pRetJSObject && JS_IsArrayBufferObject(pRetJSObject)) { uint8_t* pDataBuffer = nullptr; int dataBufferCount = 0; pDataBuffer = JS_GetArrayBufferData(pRetJSObject); dataBufferCount = JS_GetArrayBufferByteLength(pRetJSObject); pGameInfo->ParseFromArray(pDataBuffer, dataBufferCount); // RoleInfo Array for (int i = 0; i < pGameInfo->roleinfo_size(); i++) { // role info game::info::RoleInfo roleInfo = pGameInfo->roleinfo(i); CCLOG("roleInfo: \n%s\n", roleInfo.Utf8DebugString().c_str()); } // ItemInfo Array for (int i = 0; i < pGameInfo->iteminfo_size(); i++) { // role info game::info::ItemInfo itemInfo = pGameInfo->iteminfo(i); CCLOG("itemInfo: \n%s\n", itemInfo.Utf8DebugString().c_str()); } } 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); } Platform target = getTargetPlatform();//获取当前设备类型 if (target == Platform::OS_IPAD) { auto visibleSizeWidth = 1024; auto visibleSizeHeight = 768; // 根据屏幕尺寸与设计尺寸的比,重新定义设计尺寸(参考kResolutionNum来适配) auto winSize = Director::getInstance()->getWinSize(); //CCSize winSize = CCSizeMake(1136, 640);//CCEGLView::sharedOpenGLView()->getFrameSize(); if (winSize.width/winSize.height > visibleSizeWidth/visibleSizeHeight) { visibleSizeWidth = visibleSizeHeight * winSize.width/winSize.height; } else if (winSize.width/winSize.height < visibleSizeWidth/visibleSizeHeight) { visibleSizeHeight = visibleSizeWidth / (winSize.width/winSize.height); } director->getOpenGLView()->setDesignResolutionSize(visibleSizeWidth, visibleSizeHeight, ResolutionPolicy::NO_BORDER); // ipad //CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); // don't enable retina because we don't have ipad hd resource //director->getOpenGLView()->setDesignResolutionSize(800, 600, ResolutionPolicy::NO_BORDER); } else if (target == Platform::OS_IPHONE) { // 设计尺寸width、height auto visibleSizeWidth = 960; auto visibleSizeHeight = 640; // 根据屏幕尺寸与设计尺寸的比,重新定义设计尺寸(参考kResolutionNum来适配) auto winSize = Director::getInstance()->getWinSize(); //CCSize winSize = CCSizeMake(1136, 640);//CCEGLView::sharedOpenGLView()->getFrameSize(); if (winSize.width/winSize.height > visibleSizeWidth/visibleSizeHeight) { visibleSizeWidth = visibleSizeHeight * winSize.width/winSize.height; } else if (winSize.width/winSize.height < visibleSizeWidth/visibleSizeHeight) { visibleSizeHeight = visibleSizeWidth / (winSize.width/winSize.height); } //CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); //CCSize VisibleSize = CCEGLView::sharedOpenGLView()->getVisibleSize(); director->getOpenGLView()->setDesignResolutionSize(visibleSizeWidth, visibleSizeHeight, ResolutionPolicy::NO_BORDER); } else { auto visibleSizeWidth = 1152; auto visibleSizeHeight = 648; // 根据屏幕尺寸与设计尺寸的比,重新定义设计尺寸(参考kResolutionNum来适配) auto winSize = Director::getInstance()->getWinSize(); //CCSize winSize = CCSizeMake(1136, 640);//CCEGLView::sharedOpenGLView()->getFrameSize(); if (winSize.width/winSize.height > visibleSizeWidth/visibleSizeHeight) { visibleSizeWidth = visibleSizeHeight * winSize.width/winSize.height; } else if (winSize.width/winSize.height < visibleSizeWidth/visibleSizeHeight) { visibleSizeHeight = visibleSizeWidth / (winSize.width/winSize.height); } director->getOpenGLView()->setDesignResolutionSize(visibleSizeWidth, visibleSizeHeight, ResolutionPolicy::NO_BORDER); } // 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); //FileUtils::getInstance()->addSearchPath("pay_center"); // create a scene. it's an autorelease object #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) auto playVidio = PlayVedio::createScene(); HallDataMgr::getInstance()->readConfig(); CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("sound_res/LOAD_BACK.mp3",true); // run director->runWithScene(playVidio); #else auto scene = LoginLayer::createScene(); director->runWithScene(scene); HallDataMgr::getInstance()->readConfig(); CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("sound_res/LOAD_BACK.mp3",true); #endif // auto ploginlayer = static_cast<LoginLayer *>(scene->getChildByTag(10)); // ploginlayer->versionCheck(); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); auto glview = CCQGLView::getInstance(); //glview->setBgColor(Color4B(50, 50, 50, 255)); director->setOpenGLView(glview); _mainWindow.setGLView(glview->getGLWidget()); _mainWindow.initActionListWidget(); _mainWindow.show(); // 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); // create a scene. it's an autorelease object auto scene = Scene::create(); scene->setAnchorPoint(Vec2::ANCHOR_MIDDLE); scene->setContentSize(Director::getInstance()->getVisibleSize()); //scene->setPosition(Director::getInstance()->getVisibleSize() / 2); QString path; QDir dir; path = dir.currentPath(); FileUtils::getInstance()->addSearchPath(path.toStdString() + "/Resources"); FileUtils::getInstance()->addSearchPath("D://Resources"); auto keyboardEvent = EventListenerKeyboard::create(); keyboardEvent->onKeyPressed = [=](EventKeyboard::KeyCode code, Event*event) { if (code == EventKeyboard::KeyCode::KEY_CTRL) { m_dragMode = true; } }; keyboardEvent->onKeyReleased = [=](EventKeyboard::KeyCode code, Event*event) { if (code == EventKeyboard::KeyCode::KEY_CTRL) { m_dragMode = false; } }; Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(keyboardEvent, -1); auto scrollEvent = EventListenerMouse::create(); scrollEvent->onMouseScroll = [=](Event* event) { EventMouse* e = (EventMouse*)event; int scrollX = e->getScrollX(); int scrollY = e->getScrollY(); scene->setScale(scene->getScale() + (float)scrollY / 100.0f); Size currentSize = scene->getContentSize() * scene->getScale(); // scene->setScale(); }; auto eventListener = EventListenerTouchOneByOne::create(); eventListener->onTouchBegan = [=](Touch*touch, Event*event)->bool{ if (!m_dragMode) return false; return true; }; eventListener->onTouchMoved = [=](Touch*touch, Event*event) { scene->setPosition(scene->getPosition() + touch->getDelta()); }; eventListener->setSwallowTouches(true); Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(eventListener, -3); Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(scrollEvent, -2); // run director->runWithScene(scene); CCRect rect(0, 0, scene->getContentSize().width, scene->getContentSize().height); CCSprite* grid = CCSprite::create("grid1_16x16_new_aaa.png"); grid->setTextureRect(rect); Texture2D::TexParams params = { GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT }; grid->getTexture()->setTexParameters(¶ms); grid->setAnchorPoint(Vec2::ZERO); grid->setPosition(Vec2::ZERO); scene->addChild(grid,0); // return true; }
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; }
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("MadCraftWar", Rect(0, 0, designResolutionSize.width, designResolutionSize.height)); #else glview = GLViewImpl::create("MadCraftWar"); #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); // Set the design resolution glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER); Size frameSize = glview->getFrameSize(); if (frameSize.height > mediumResolutionSize.height) { // if the frame's height is larger than the height of medium size. director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width)); } else if (frameSize.height > smallResolutionSize.height) { // if the frame's height is larger than the height of small size. director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width)); } else { // if the frame's height is smaller than the height of medium size. director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width)); } register_all_packages(); // Load game resource //SpriteFrameCache::getInstance()->addSpriteFrame(SpriteFrame::create("monster.png", Rect(0, 0, 48, 72)), "monster.png"); SpriteFrameCache::getInstance()->addSpriteFramesWithFile("game-sheet.plist"); // Explosion animation char frameName[64]; Animation * animation = Animation::create(); for (int i = 0; i < 15; ++i) { sprintf(frameName, "explosion-%d.png", i); animation->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(frameName)); } animation->setDelayPerUnit(0.1f); AnimationCache::getInstance()->addAnimation(animation, "ExplosionAnimation"); CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic("background.mp3"); CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("fire.wav"); CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("explosion.wav"); CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("hurt.wav"); // create a scene. it's an autorelease object auto scene = GameScene::createScene(); // run director->runWithScene(scene); return true; }