bool AppDelegate::applicationDidFinishLaunching() { preInitAPI(); // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); // 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); //check for first launch if( getSystem()->isFirstLaunch() ){ //clear update folder CCLOG("-- FIRST LAUNCH --"); string docpath; getSystem()->getDocumentPath(docpath); string udpath = docpath + "update/"; getSystem()->removeDirectory(udpath); string dypath = docpath + "dynamic.json"; getSystem()->removeDirectory(dypath); } CCDictionary *pSetup = CCDictionary::createWithContentsOfFile("Setup.plist"); string display; {//set display CCSize winSize = pDirector->getWinSize(); float aspectRatio = winSize.height/winSize.width; CCArray *pResolutions = (CCArray*)pSetup->objectForKey("Resolutions"); if( pResolutions != NULL ) { float fitScore = 10; float fitWidth = 0; float fitHeight = 0; bool isFitable = false; CCObject *pObj = NULL; CCARRAY_FOREACH(pResolutions, pObj) { CCDictionary *pRes = (CCDictionary*)pObj; CCString *pPath = (CCString*)pRes->objectForKey("path"); CCString *pWidth = (CCString*)pRes->objectForKey("width"); CCString *pHeight = (CCString*)pRes->objectForKey("height"); float width, height, score; sscanf(pWidth->getCString(), "%f", &width); sscanf(pHeight->getCString(), "%f", &height); if (winSize.height == height) { isFitable = true; } if( winSize.width >= width && winSize.height >= height ) { score = 0; float aspect = height/width; float dist = fabsf(aspect - aspectRatio); if( dist < fitScore ) { fitScore = dist; fitWidth = width; fitHeight = height; display = pPath->getCString(); } } else { score = 8; } } if(fitWidth == 0 || fitHeight == 0) { fitWidth = 640; fitHeight = 960; display = "960/"; } //set best resolution if (isFitable){ pDirector->getOpenGLView()->setDesignResolutionSize(fitWidth, fitHeight, kResolutionShowAll); } getSystem()->setViewSizeHeight((int)fitHeight); getSystem()->setViewSizeWidth((int)fitWidth); CCLog("Resolution Adapter: %dx%d (%s) = %f", (int)fitWidth, (int)fitHeight, display.c_str(), fitScore); }
void ModalLayer::menuCloseCallback(CCObject* pSender) { this->removeFromParentAndCleanup(true); CCDirector* pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->removeDelegate(this); }
void HUILayer::onOK() { CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->end(); }
bool AppDelegate::applicationDidFinishLaunching() { CCDirector* director = CCDirector::sharedDirector(); CCEGLView* EGLView = CCEGLView::sharedOpenGLView(); CCSize screenSize = EGLView->getFrameSize(); #if CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID soomla::CCSoomla::sharedSoomla()->addEventHandler(handler); InAppPurchasesList *assets = InAppPurchasesList::create(); CCDictionary *storeParams = CCDictionary::create(); storeParams->setObject(CCString::create(Options::SOOMLA_BASE_64_KEY), "soomSec"); #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID storeParams->setObject(CCString::create(Options::GOOGLE_PLAY_BASE_64_KEY), "androidPublicKey"); #endif storeParams->setObject(CCString::create(Options::SOOMLA_CUSTOM_BASE_64_KEY), "customSecret"); #if COCOS2D_DEBUG >= 1 && CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID storeParams->setObject(CCBool::create(true), "androidTestMode"); #endif soomla::CCStoreController::createShared(assets, storeParams); #endif #if CC_TARGET_PLATFORM == CC_PLATFORM_IOS if(screenSize.width >= 2048) { Options::designResolutionSize = CCSizeMake(1920, 1280); } else { Options::designResolutionSize = CCSizeMake(720, 1280); } #elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID //Options::designResolutionSize = CCSizeMake(270, 480); Options::designResolutionSize = CCSizeMake(720, 1280); #elif CC_TARGET_PLATFORM == CC_PLATFORM_WINRT Options::designResolutionSize = CCSizeMake(1920, 1280); #else Options::designResolutionSize = CCSizeMake(720, 1280); #endif director->setOpenGLView(EGLView); director->setContentScaleFactor(Options::designResolutionSize.height / screenSize.height); Options::SCREEN_WIDTH = Options::designResolutionSize.width; Options::SCREEN_HEIGHT = Options::designResolutionSize.height; Options::SCREEN_CENTER_X = Options::designResolutionSize.width / 2; Options::SCREEN_CENTER_Y = Options::designResolutionSize.height / 2; Options::CAMERA_WIDTH = screenSize.width; Options::CAMERA_HEIGHT = screenSize.height; Options::CAMERA_CENTER_X = screenSize.width / 2; Options::CAMERA_CENTER_Y = screenSize.height / 2; vector <string> searchPath; #if CC_TARGET_PLATFORM == CC_PLATFORM_IOS { if(Options::CAMERA_WIDTH >= 2048) { searchPath.push_back(resources2048x1536.directory); Options::DEVICE_TYPE = Options::DEVICE_TYPE_IPAD_RETINA; } else { if(Options::CAMERA_HEIGHT == 960) { searchPath.push_back(resources1280x720xPVRTC2.directory); Options::DEVICE_TYPE = Options::DEVICE_TYPE_IPHONE4; if(AppDelegate::IS_IPOD) { Options::DEVICE_TYPE = Options::DEVICE_TYPE_IPOD4; } } else { searchPath.push_back(resources1280x720.directory); Options::DEVICE_TYPE = Options::DEVICE_TYPE_IPHONE5; } } } #elif CC_TARGET_PLATFORM == CC_PLATFORM_MAC searchPath.push_back(resources1920x1080.directory); Options::DEVICE_TYPE = Options::DEVICE_TYPE_MAC; #elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID if(Options::CAMERA_HEIGHT == 1184) { Options::DEVICE_TYPE = Options::DEVICE_TYPE_NEXUS3; searchPath.push_back(resources1280x720.directory); } else if(Options::CAMERA_HEIGHT < 720) { Options::DEVICE_TYPE = Options::DEVICE_TYPE_IPHONE5; searchPath.push_back(resources480x320.directory); } else { Options::DEVICE_TYPE = Options::DEVICE_TYPE_IPHONE5; searchPath.push_back(resources1280x720.directory); } #elif CC_TARGET_PLATFORM == CC_PLATFORM_WP8 searchPath.push_back(resources1280x720.directory); Options::DEVICE_TYPE = Options::DEVICE_TYPE_MAC; #else Options::DEVICE_TYPE = Options::DEVICE_TYPE_WINDOWS; searchPath.push_back(resources1920x1080.directory); #endif CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath); director->setDisplayStats(false); director->setProjection(kCCDirectorProjection2D); director->setAnimationInterval(1.0f / 60.0f); if(!AppDelegate::isInstalled() || AppDelegate::lastVersion() != Options::VERSION) { AppDelegate::install(false); // NOT SOFT INSTALLATION } Options::init(); Screen* pScene = SplashScreen::create(); director->runWithScene(pScene); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); CCEGLView* pEglView = CCEGLView::sharedOpenGLView(); pDirector->setOpenGLView(pEglView); // Set resolution size and paths pEglView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder); CCSize frameSize = pEglView->getFrameSize(); vector<string> searchPaths; if(frameSize.width < designResolutionSize.width) { } /* if(frameSize.height > smallResource.size.height) { searchPaths.push_back(mediumResource.directory); pDirector->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width)); } else { searchPaths.push_back(smallResource.directory); pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width)); } */ searchPaths.push_back(mediumResource.directory); pDirector->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width)); searchPaths.push_back("audio"); CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths); SimpleAudioEngine::sharedEngine()->preloadEffect(SFX_JUMP); SimpleAudioEngine::sharedEngine()->preloadEffect(SFX_SWOOSH); SimpleAudioEngine::sharedEngine()->preloadEffect(SFX_SMASH); SimpleAudioEngine::sharedEngine()->preloadEffect(SFX_BUTTON); SimpleAudioEngine::sharedEngine()->preloadEffect(SFX_LIGHTNING); SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(BG_MUSIC_01); SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(BG_MUSIC_02); SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(BG_MUSIC_03); SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(BG_MUSIC_VOLUME); SimpleAudioEngine::sharedEngine()->setEffectsVolume(1.0f); // turn on display FPS pDirector->setDisplayStats(SHOW_FPS); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object CCScene *pScene = HomeScene::scene(kGameModeHome); // run pDirector->runWithScene(pScene); return true; }
void JSTouchDelegate::registerStandardDelegate() { CCDirector* pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->addStandardDelegate(this,0); }
void MainMenu::northPoleSceneCallback(CCObject* pSender){ CCDirector *director = CCDirector::sharedDirector(); director->replaceScene(FarmScene::farmScene()); }
void AppDelegate::initGameView() { // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); pDirector->setProjection(kCCDirectorProjection2D); CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize(); if(!isPortraitApp) { screenSize = CCSizeMake(screenSize.height, screenSize.width); } std::vector<std::string> resDirOrders; std::string res; TargetPlatform platform = CCApplication::sharedApplication()->getTargetPlatform(); if (platform == kTargetIphone || platform == kTargetIpad) { std::vector<std::string> searchPaths = CCFileUtils::sharedFileUtils()->getSearchPaths(); searchPaths.insert(searchPaths.begin(), "Published files iOS"); searchPaths.insert(searchPaths.begin(), getCCBDirectoryPath()); CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths); if (screenSize.height > 1136) { res = "iPad"; setResolutionSizes(true, true, isPortraitApp); resDirOrders.push_back("resources-ipadhd"); resDirOrders.push_back("resources-ipad"); resDirOrders.push_back("resources-iphonehd"); isIPhone = false; isRetina = true; cocos2d::extension::CCBReader::setResolutionScale(2); } else if(screenSize.height > 1024) { res = "iPhone"; setResolutionSizes(false, true, isPortraitApp); resDirOrders.push_back("resources-iphonehd"); resDirOrders.push_back("resources-iphone"); isIPhone = true; isRetina = true; } else if (screenSize.height > 960) { res = "iPad"; setResolutionSizes(true, false, isPortraitApp); resDirOrders.push_back("resources-ipad"); resDirOrders.push_back("resources-iphonehd"); isIPhone = false; isRetina = false; cocos2d::extension::CCBReader::setResolutionScale(2); } else if (screenSize.height > 480) { res = "iPhone"; setResolutionSizes(false, true, isPortraitApp); resDirOrders.push_back("resources-iphonehd"); resDirOrders.push_back("resources-iphone"); isIPhone = true; isRetina = true; } else { res = "iPhone"; setResolutionSizes(false, false, isPortraitApp); resDirOrders.push_back("resources-iphone"); isIPhone = true; isRetina = false; } } else if (platform == kTargetAndroid || platform == kTargetWindows) { int dpi = -1; dpi = CCDevice::getDPI(); if(dpi > 300) { // retina if (screenSize.height > 1920) { res = "xlarge"; setResolutionSizes(true, true, isPortraitApp); resDirOrders.push_back("resources-xlarge"); resDirOrders.push_back("resources-large"); resDirOrders.push_back("resources-medium"); resDirOrders.push_back("resources-small"); } else { res = "large"; setResolutionSizes(false, true, isPortraitApp); resDirOrders.push_back("resources-large"); resDirOrders.push_back("resources-medium"); resDirOrders.push_back("resources-small"); } } else { // non retina if (screenSize.height > 960) { res = "large"; setResolutionSizes(true, false, isPortraitApp); resDirOrders.push_back("resources-large"); resDirOrders.push_back("resources-medium"); resDirOrders.push_back("resources-small"); cocos2d::extension::CCBReader::setResolutionScale(2); } else if (screenSize.height > 768) { res = "medium"; setResolutionSizes(true, false, isPortraitApp); resDirOrders.push_back("resources-medium"); resDirOrders.push_back("resources-small"); } else if (screenSize.height > 480) { res = "small"; setResolutionSizes(false, false, isPortraitApp); resDirOrders.push_back("resources-small"); } else { setResolutionSizes(false, false, isPortraitApp); res = "xsmall"; resDirOrders.push_back("resources-xsmall"); } } } CCFileUtils *pFileUtils = CCFileUtils::sharedFileUtils(); pFileUtils->setSearchResolutionsOrder(resDirOrders); std::vector<std::string> searchPaths = pFileUtils->getSearchPaths(); searchPaths.insert(searchPaths.begin(), pFileUtils->getWritablePath()); pFileUtils->setSearchPaths(searchPaths); PlayerStatus::setDeviceResolution(res); // turn on display FPS pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); }
void HelloWorld::onEnter(){ CCDirector* pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true); }
void CCLayer::registerWithTouchDispatcher() { CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->addStandardDelegate(this, 0); }
void TaskChatLayer::registerWithTouchDispatcher() { CCDirector* pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->addTargetedDelegate(this, kCCScrollTouchBgPriority, true); }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize(); CCSize designSize = CCSizeMake(480, 320); std::vector<std::string> searchPaths; if (screenSize.height > 320) { searchPaths.push_back("hd"); searchPaths.push_back("sd"); pDirector->setContentScaleFactor(640.0f/designSize.height); } else { searchPaths.push_back("sd"); pDirector->setContentScaleFactor(320.0f/designSize.height); } CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths); CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionExactFit); // turn on display FPS pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object CCScene *pScene = HelloWorld::scene(); // run pDirector->runWithScene(pScene); return true; // // initialize director // CCDirector* pDirector = CCDirector::sharedDirector(); // CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); // // pDirector->setOpenGLView(pEGLView); // CCSize visibleSize = pDirector->getVisibleSize(); // // Set the design resolution // pEGLView->setDesignResolutionSize(visibleSize.width, // visibleSize.height, kResolutionShowAll); // CCSize frameSize = pEGLView->getFrameSize(); // cocos2d::CCLog("frameSize.width=%2f, frameSize.height=%2f",frameSize.width, frameSize.height); // //// float ratio = frameSize.width / frameSize.height; //// float ratio1 = largeDesignResolutionSize.width / largeDesignResolutionSize.height; //// float ratio2 = mediumDesignResolutionSize.width / mediumDesignResolutionSize.height; //// float ratio3 = smallDesignResolutionSize.width / smallDesignResolutionSize.height; //// float d1 = abs(ratio - ratio1); //// float d2 = abs(ratio - ratio2); //// float d3 = abs(ratio - ratio3); //// std::map<float, CCSize> designSize; //// designSize[d1] = largeDesignResolutionSize; //// designSize[d2] = mediumDesignResolutionSize; //// designSize[d3] = smallDesignResolutionSize; //// std::map<float, CCSize>::reverse_iterator iter = designSize.rbegin(); // // //得到key最大的,因此我这里是横屏,所以以高度为基准,为了确保缩放后宽度能全屏,所以选取宽高比最大的为设计方案 //// CCSize designResolutionSize = iter->second; // // //pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder); //// pEGLView->setDesignResolutionSize(designResolutionSize.width, //// designResolutionSize.height, kResolutionShowAll); // // //pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionExactFit); // //// if (frameSize.height > mediumResource.size.height) { //// CCFileUtils::sharedFileUtils()->setResourceDirectory( //// largeResource.directory); //// pDirector->setContentScaleFactor( //// largeResource.size.height / designResolutionSize.height); //// } else if (frameSize.height > smallResource.size.height) { //// CCFileUtils::sharedFileUtils()->setResourceDirectory( //// mediumResource.directory); //// pDirector->setContentScaleFactor( //// mediumResource.size.height / designResolutionSize.height); //// } else { //// CCFileUtils::sharedFileUtils()->setResourceDirectory( //// smallResource.directory); //// pDirector->setContentScaleFactor( //// smallResource.size.height / designResolutionSize.height); //// } // // std::vector<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); // // pDirector->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); // // pDirector->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); // // pDirector->setContentScaleFactor( // MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width)); // } // // // set searching path // CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath); // // // turn on display FPS // pDirector->setDisplayStats(true); // // // set FPS. the default value is 1.0/60 if you don't call this // pDirector->setAnimationInterval(1.0 / 60); // // // create a scene. it's an autorelease object // CCScene *pScene = HelloWorld::scene(); // // // run // pDirector->runWithScene(pScene); // // return true; }
void Menu::registerWithTouchDispatcher() { CCDirector* pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->addTargetedDelegate(this, kCCMenuHandlerPriority + 1, true); }
void KeyboardNotificationLayer::registerWithTouchDispatcher() { CCDirector* pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, false); }
void GameObjHero::onExit() { CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->removeDelegate(this); CCNode::onExit(); }
void HelloWorld::onExit(){ CCDirector* pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->removeDelegate(this); }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector* pDirector = CCDirector::sharedDirector(); CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); CCSize frameSize = pEGLView->getFrameSize(); pDirector->setOpenGLView(pEGLView); std::vector<std::string> searchPaths; #if MC_ADAPTIVE_RESOLUTION == 1 // Set the design resolution #if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) pEGLView->setDesignResolutionSize(PCResource.size.width, PCResource.size.height, kResolutionExactFit); searchPaths.push_back(PCResource.directory); // pDirector->setContentScaleFactor(MIN(32 * 25 / PCResource.size.width, 32 * 15 / PCResource.size.height)); // pDirector->setContentScaleFactor(0.75f); pDirector->setContentScaleFactor(MIN(32 * 25 / frameSize.width, 32 * 15 / frameSize.height)); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) // if the frame's height is larger than the height of medium resource size, select large resource. if (frameSize.height == smallResource.size.height) { pEGLView->setDesignResolutionSize(smallResource.size.width, smallResource.size.height, kResolutionNoBorder); searchPaths.push_back(smallResource.directory); } // if the frame's height is larger than the height of small resource size, select medium resource. else if (frameSize.height == mediumResource.size.height) { pEGLView->setDesignResolutionSize(mediumResource.size.width, mediumResource.size.height, kResolutionNoBorder); searchPaths.push_back(mediumResource.directory); } // if the frame's height is smaller than the height of medium resource size, select small resource. else { pEGLView->setDesignResolutionSize(largeResource.size.width, largeResource.size.height, kResolutionNoBorder); searchPaths.push_back(largeResource.directory); } pDirector->setContentScaleFactor(MIN(32 * 25 / frameSize.width, 32 * 15 / frameSize.height)); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) int i = 0; int size = sizeof(resources); int found = 0; for (; i < size; ++i) { if ((frameSize.width == resources[i].size.width && frameSize.height == resources[i].size.height) || (frameSize.width == resources[i].size.height && frameSize.height == resources[i].size.width)) { searchPaths.push_back(resources[i].directory); pEGLView->setDesignResolutionSize(resources[i].size.width, resources[i].size.height, kResolutionNoBorder); pDirector->setContentScaleFactor(MIN(32 * 25 / resources[i].size.width, 32 * 15 / resources[i].size.height)); found = 1; break; } } if (found == 0) { searchPaths.push_back(resources[0].directory); pEGLView->setDesignResolutionSize(resources[0].size.width, resources[0].size.height, kResolutionNoBorder); pDirector->setContentScaleFactor(MIN(32 * 25 / resources[0].size.width, 32 * 15 / resources[0].size.height)); } #else // if the frame's height is larger than the height of medium resource size, select large resource. if (frameSize.height > mediumResource.size.height) { searchPaths.push_back(largeResource.directory); pEGLView->setDesignResolutionSize(largeResource.size.width, largeResource.size.height); pDirector->setContentScaleFactor(MIN(largeResource.size.height/smallResource.size.height, largeResource.size.width/smallResource.size.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) { searchPaths.push_back(mediumResource.directory); pEGLView->setDesignResolutionSize(mediumResource.size.width, mediumResource.size.height); pDirector->setContentScaleFactor(MIN(mediumResource.size.height/smallResource.size.height, mediumResource.size.width/smallResource.size.width)); } // if the frame's height is smaller than the height of medium resource size, select small resource. else { searchPaths.push_back(smallResource.directory); pEGLView->setDesignResolutionSize(smallResource.size.width, smallResource.size.height); pDirector->setContentScaleFactor(MIN(smallResource.size.height, smallResource.size.width)); } #endif // platforms #else CCSize designSize = CCSizeMake(960, 640); searchPaths.push_back(CommonResource.directory); if (frameSize.height > 1280) { CCSize resourceSize = CCSizeMake(2048, 1536); std::vector<std::string> searchPaths; // searchPaths.push_back("hd"); //没资源 pDirector->setContentScaleFactor(0.75 * resourceSize.height / designSize.height); } else { pDirector->setContentScaleFactor(0.75); } CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionFixedWidth); #endif // MC_ADAPTIVE_RESOLUTION == 0 CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths); // 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); CCLog("%s(%d): %.0f %.0f %.0f", __FILE__, __LINE__, frameSize.width, frameSize.height, pDirector->getContentScaleFactor()); // register lua engine CCLuaEngine* pEngine = CCLuaEngine::defaultEngine(); CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine); #if MC_DEBUG_SERVER == 1 MCSimpleGameSceneContextServer *server = MCSimpleGameSceneContextServer::defaultSimpleGameSceneContextServer(); server->setPort(kMCListeningPort); server->runloop(); #endif // run // pDirector->pushScene(MCMainMenuLayer::scene()); // pDirector->runWithScene(MCSplashLayer::scene()); pDirector->runWithScene(MCTestbed::scene()); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); pDirector->setProjection(kCCDirectorProjection2D); CCSize screenSize = CCEGLView::sharedOpenGLView()->getFrameSize(); CCSize designSize = CCSizeMake(320, 480); CCSize resourceSize = CCSizeMake(640, 960); std::vector<std::string> searchPaths; std::vector<std::string> resDirOrders; TargetPlatform platform = CCApplication::sharedApplication()->getTargetPlatform(); if (platform == kTargetIphone || platform == kTargetIpad) { searchPaths.push_back("js"); // Resources/Published-iOS searchPaths.push_back("data"); searchPaths.push_back("Published-iOS"); searchPaths.push_back("res"); CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths); if (screenSize.height > 480) { resourceSize = CCSizeMake(640, 960); resDirOrders.push_back("resources-iphonehd"); } else { resDirOrders.push_back("resources-iphone"); } CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders); } else if (platform == kTargetAndroid || platform == kTargetWindows) { if(platform == kTargetWindows) { searchPaths.push_back("../../js"); searchPaths.push_back("../../jslib"); searchPaths.push_back("../../data"); searchPaths.push_back("../../AnotherWorld/Published-iOS"); searchPaths.push_back("../../res"); } searchPaths.push_back("AnotherWorldRes"); CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths); // Comments it since opengles2.0 only supports texture size within 2048x2048. // if (screenSize.height > 1024) // { // resourceSize = CCSizeMake(1280, 1920); // resDirOrders.push_back("resources-xlarge"); // resDirOrders.push_back(""); // } // else if (screenSize.height > 960) { resourceSize = CCSizeMake(640, 960); resDirOrders.push_back("resources-large"); resDirOrders.push_back("resources-medium"); resDirOrders.push_back("resources-small"); } else if (screenSize.height > 480) { resourceSize = CCSizeMake(480, 720); resDirOrders.push_back("resources-medium"); resDirOrders.push_back("resources-small"); } else { resourceSize = CCSizeMake(320, 568); resDirOrders.push_back("resources-small"); } resDirOrders.push_back("resources-iphone"); CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(resDirOrders); } pDirector->setContentScaleFactor(resourceSize.width/designSize.width); CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionShowAll); // turn on display FPS pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); ScriptingCore* sc = ScriptingCore::getInstance(); sc->addRegisterCallback(register_all_cocos2dx); sc->addRegisterCallback(register_all_cocos2dx_extension); sc->addRegisterCallback(register_cocos2dx_js_extensions); sc->addRegisterCallback(register_all_cocos2dx_extension_manual); sc->addRegisterCallback(register_CCBuilderReader); sc->addRegisterCallback(jsb_register_system); sc->start(); js_log("RUNNING Main"); CCScriptEngineProtocol *pEngine = ScriptingCore::getInstance(); CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine); ScriptingCore::getInstance()->runScript("app.js"); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector* pDirector = CCDirector::sharedDirector(); CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); pDirector->setOpenGLView(pEGLView); CCSize frameSize = pEGLView->getFrameSize(); // Set the design resolution #if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionShowAll); #else pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder); #endif vector<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); pDirector->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); pDirector->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); pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width)); } // set searching path CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath); // turn on display FPS // pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object CCScene *scene = nullptr; scene = MenuLayer::scene(); //scene = VisionClipper::testScene(); // run pDirector->runWithScene(scene); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); pDirector->setOpenGLView(pEGLView); // CCSize frameSize = pEGLView->getFrameSize(); // // Set the design resolution //#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) // pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionShowAll); //#else // pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder); //#endif // vector<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); // // pDirector->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); // // pDirector->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); // // pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width)); // } // // // set searching path searchPath.push_back("BattleScene01/Resources"); CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath); CCSize designSize = CCSizeMake(960, 640); CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder); // CCEGLView *pView=pDirector->getOpenGLView(); // pView->setDesignResolutionSize(480,320,kResolutionNoBorder); // CCDirector::sharedDirector()->setContentScaleFactor(2.0); // 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); InitGameConfig(); #if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 // set resource folder std::string exeWin32Path = CCFileUtils::sharedFileUtils()->getWritablePath(); exeWin32Path = exeWin32Path + "..\\..\\Resources"; this->setResourceRootPath(exeWin32Path); #endif //SkeletonAnimRcsManager::Get()->LoadAllAnimConnectionData(); //std::string _path = GameResourceManager::sharedManager()->storedFullPathFromRelativePath("Data"); //CCScene* pScene = CCScene::create(); //MainScene* pLayer = MainScene::create(); //pScene->addChild(pLayer); //pLayer->Run(); //pLayer->TestParticle(); //CCDirector::sharedDirector()->runWithScene(pScene); XLogicManager::sharedManager()->startGame(); return true; }
void MainMenu::menuPlayBeginCallback(CCObject* pSender){ CCDirector *director = CCDirector::sharedDirector(); director->replaceScene(FarmScene::farmScene()); }
LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { BOOL bProcessed = FALSE; switch (message) { case WM_LBUTTONDOWN: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_pDelegate && MK_LBUTTON == wParam) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x, point.y); pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp)) { m_bCaptured = true; SetCapture(m_hWnd); int id = 0; handleTouchesBegin(1, &id, &pt.x, &pt.y); } } break; case WM_MOUSEMOVE: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (MK_LBUTTON == wParam && m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x, point.y); int id = 0; pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; handleTouchesMove(1, &id, &pt.x, &pt.y); } break; case WM_LBUTTONUP: #if(_MSC_VER >= 1600) // Don't process message generated by Windows Touch if (m_bSupportTouch && (s_pfGetMessageExtraInfoFunction() & MOUSEEVENTF_FROMTOUCH) == MOUSEEVENTF_FROMTOUCH) break; #endif /* #if(_MSC_VER >= 1600) */ if (m_bCaptured) { POINT point = {(short)LOWORD(lParam), (short)HIWORD(lParam)}; CCPoint pt(point.x, point.y); int id = 0; pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; handleTouchesEnd(1, &id, &pt.x, &pt.y); ReleaseCapture(); m_bCaptured = false; } break; #if(_MSC_VER >= 1600) case WM_TOUCH: { BOOL bHandled = FALSE; UINT cInputs = LOWORD(wParam); PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs]; if (pInputs) { if (s_pfGetTouchInputInfoFunction((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT))) { for (UINT i=0; i < cInputs; i++) { TOUCHINPUT ti = pInputs[i]; POINT input; input.x = TOUCH_COORD_TO_PIXEL(ti.x); input.y = TOUCH_COORD_TO_PIXEL(ti.y); ScreenToClient(m_hWnd, &input); CCPoint pt(input.x, input.y); CCPoint tmp = ccp(pt.x, m_obScreenSize.height - pt.y); if (m_obViewPortRect.equals(CCRectZero) || m_obViewPortRect.containsPoint(tmp)) { pt.x /= m_fFrameZoomFactor; pt.y /= m_fFrameZoomFactor; if (ti.dwFlags & TOUCHEVENTF_DOWN) handleTouchesBegin(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y); else if (ti.dwFlags & TOUCHEVENTF_MOVE) handleTouchesMove(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y); else if (ti.dwFlags & TOUCHEVENTF_UP) handleTouchesEnd(1, reinterpret_cast<int*>(&ti.dwID), &pt.x, &pt.y); } } bHandled = TRUE; } delete [] pInputs; } if (bHandled) { s_pfCloseTouchInputHandleFunction((HTOUCHINPUT)lParam); } } break; #endif /* #if(_MSC_VER >= 1600) */ case WM_SIZE: switch (wParam) { case SIZE_RESTORED: CCApplication::sharedApplication()->applicationWillEnterForeground(); break; case SIZE_MINIMIZED: CCApplication::sharedApplication()->applicationDidEnterBackground(); break; } break; case WM_KEYDOWN: if (wParam == VK_F1 || wParam == VK_F2) { CCDirector* pDirector = CCDirector::sharedDirector(); if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0) pDirector->getKeypadDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked); } else if (wParam == VK_ESCAPE) { CCDirector::sharedDirector()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeBackClicked); } if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } break; case WM_KEYUP: if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } break; case WM_CHAR: { if (wParam < 0x20) { if (VK_BACK == wParam) { CCIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward(); } else if (VK_RETURN == wParam) { CCIMEDispatcher::sharedDispatcher()->dispatchInsertText("\n", 1); } else if (VK_TAB == wParam) { // tab input } else if (VK_ESCAPE == wParam) { // ESC input //CCDirector::sharedDirector()->end(); } } else if (wParam < 128) { // ascii char CCIMEDispatcher::sharedDispatcher()->dispatchInsertText((const char *)&wParam, 1); } else { char szUtf8[8] = {0}; int nLen = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&wParam, 1, szUtf8, sizeof(szUtf8), NULL, NULL); CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(szUtf8, nLen); } if ( m_lpfnAccelerometerKeyHook!=NULL ) { (*m_lpfnAccelerometerKeyHook)( message,wParam,lParam ); } } break; case WM_PAINT: PAINTSTRUCT ps; BeginPaint(m_hWnd, &ps); EndPaint(m_hWnd, &ps); break; case WM_CLOSE: CCDirector::sharedDirector()->end(); break; case WM_DESTROY: destroyGL(); //PostQuitMessage(0); //CHANGED_BY_FJZ break; default: if (m_wndproc) { m_wndproc(message, wParam, lParam, &bProcessed); if (bProcessed) break; } return DefWindowProc(m_hWnd, message, wParam, lParam); } if (m_wndproc && !bProcessed) { m_wndproc(message, wParam, lParam, &bProcessed); } return 0; }
bool AppDelegate::applicationDidFinishLaunching() { /** * The initialization of StoreController. This is the first and ONLY time it's initialized. **/ cocos2dx_StoreController::initialize("ExampleCustomSecret"); cocos2dx_EventHandlers::getInstance()->addHandler(handler); // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); TargetPlatform target = getTargetPlatform(); if (target == kTargetIpad) { // ipad CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); // don't enable retina because we don't have ipad hd resource CCEGLView::sharedOpenGLView()->setDesignResolutionSize(960, 640, kResolutionNoBorder); } else if (target == kTargetIphone) { // iphone // if (pDirector->enableRetinaDisplay(true)) // { // iphone hd CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); // } // else // { // CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone"); // } CCEGLView::sharedOpenGLView()->setDesignResolutionSize(720, 1280, kResolutionNoBorder); } else { // android, windows, blackberry, linux or mac // use 960*640 resources as design resolution size CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); CCEGLView::sharedOpenGLView()->setDesignResolutionSize(720, 1280, kResolutionNoBorder); } // turn on display FPS pDirector->setDisplayStats(false); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object CCScene *pScene = MainScene::scene(); // run pDirector->runWithScene(pScene); return true; }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector* pDirector = CCDirector::sharedDirector(); CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); pDirector->setOpenGLView(pEGLView); // Set the design resolution pEGLView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder); CCSize frameSize = pEGLView->getFrameSize(); vector<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); pDirector->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); pDirector->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); pDirector->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width)); } // set searching path CCFileUtils::sharedFileUtils()->setSearchPaths(searchPath); // turn on display FPS pDirector->setDisplayStats(false); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object //directly jump to the human play menu /*AcquireGameScene::loadTexture(); AcquireSelectScene *pScene = AcquireSelectScene::create(); AcquireGameScene* pGameScene = AcquireGameScene::create(); pGameScene->initGameWithSelection( pScene ); pDirector->runWithScene(pGameScene);*/ //directly jump to the end play menu /*AcquireGameScene::loadTexture(); AcquireSelectScene *pScene = AcquireSelectScene::create(); AcquireGameScene* pGameScene = AcquireGameScene::create(); pGameScene->initGameWithSelection( pScene ); CCScene *s = AcquireGameScene::create_gameend_scene(); s->addChild( pGameScene->create_static_layer() ); pDirector->runWithScene(s);*/ //AcquireGameScene *pScene = AcquireGameScene::create(); //AcquireGameScene::loadTexture(); //AcquireSelectScene *pScene = AcquireSelectScene::create(); //CCScene *pScene = AcquireGameScene::create_splash_scene(); //CCScene *pScene = AcquireGameScene::create_gameend_scene(); //pDirector->runWithScene(pScene); //pScene ->switchToGameScene(NULL); //pDirector->runWithScene( pScene->create_gameend_scene() ); //standard procedure CCScene *pScene = AcquireGameScene::create_splash_scene(); pDirector->runWithScene(pScene); return true; }
bool MPTitleLayer::init() { CCDirector * director = CCDirector::sharedDirector(); CCPoint origin = director->getVisibleOrigin(); float h = director->getVisibleSize().height; float w = director->getVisibleSize().width; // CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); // CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); // Scene title CCLabelTTF * pLabel = CCLabelTTF::create("Title Scene", "Arial", TITLE_FONT_SIZE); pLabel->setPosition( ccp(origin.x + w/2, origin.y + h - pLabel->getContentSize().height) ); this->addChild(pLabel, 1); // Layout the selectable labels. int yInc = 70; int xPos = w/2; int yPos = h - 2* yInc; // Box2D menu item label CCLabelTTF * box2DLabel = CCLabelTTF::create("Box 2D Scene", "Arial", TITLE_FONT_SIZE); box2DLabel->setPosition(CCPointZero); CCMenuItemLabel * box2DItem = CCMenuItemLabel::create(box2DLabel, this, menu_selector(MPTitleLayer::selectBox2D)); box2DItem->setPosition(xPos, yPos); // GUI Test menu item label yPos -= yInc; CCLabelTTF * guiTestLabel = CCLabelTTF::create("GUI Test Scene", "Arial", TITLE_FONT_SIZE); guiTestLabel->setPosition(CCPointZero); CCMenuItemLabel * guiTestItem = CCMenuItemLabel::create(guiTestLabel, this, menu_selector(MPTitleLayer::selectGuiTest)); guiTestItem->setPosition(xPos, yPos); // Audio Button yPos -= yInc; CCLabelTTF * audioLabel = CCLabelTTF::create("Audio Scene", "Arial", TITLE_FONT_SIZE); audioLabel->setPosition(CCPointZero); CCMenuItemLabel * audioItem = CCMenuItemLabel::create(audioLabel, this, menu_selector(MPTitleLayer::selectAudio)); audioItem->setPosition(xPos, yPos); // Map Button yPos -= yInc; CCLabelTTF * mapLabel = CCLabelTTF::create("Map Scene", "Arial", TITLE_FONT_SIZE); mapLabel->setPosition(CCPointZero); CCMenuItemLabel * mapItem = CCMenuItemLabel::create(mapLabel, this, menu_selector(MPTitleLayer::selectMap)); mapItem->setPosition(xPos, yPos); // Turner Map Button yPos -= yInc; CCLabelTTF* turnerMapLabel = CCLabelTTF::create("Turner Map Scene", "Arial", TITLE_FONT_SIZE); turnerMapLabel->setPosition(CCPointZero); CCMenuItemLabel * turnerMapItem = CCMenuItemLabel::create(turnerMapLabel, this, menu_selector(MPTitleLayer::selectTurnerMap)); turnerMapItem->setPosition(xPos, yPos); // Close button CCMenuItemImage * closeItem = CCMenuItemImage::create("CloseNormal.png", "CloseSelected.png", this, menu_selector(MPTitleLayer::menuCloseCallback)); closeItem->setPosition( ccp( origin.x + w - closeItem->getContentSize().width/2 , origin.y + closeItem->getContentSize().height/2 ) ); // Menu container CCMenu * menu = CCMenu::create(box2DItem, guiTestItem, audioItem, mapItem, turnerMapItem, closeItem, NULL); menu->setPosition(CCPointZero); this->addChild(menu, 1); return true; }
void Paddle::onEnter() { CCDirector* pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true); CCSprite::onEnter(); }
void GiftListView::registerWithTouchDispatcher() { CCDirector* pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->addTargetedDelegate(this, getTouchPriority(), true); }
void Paddle::onExit() { CCDirector* pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->removeDelegate(this); CCSprite::onExit(); }
CCNode::CCNode(void) : m_fRotationX(0.0f) , m_fRotationY(0.0f) , m_fScaleX(1.0f) , m_fScaleY(1.0f) , m_fVertexZ(0.0f) , m_obPosition(CCPointZero) , m_fSkewX(0.0f) , m_fSkewY(0.0f) , m_obAnchorPointInPoints(CCPointZero) , m_obAnchorPoint(CCPointZero) , m_obContentSize(CCSizeZero) , m_sAdditionalTransform(CCAffineTransformMakeIdentity()) , m_pCamera(NULL) // children (lazy allocs) // lazy alloc , m_pGrid(NULL) , m_nZOrder(0) , m_pChildren(NULL) , m_pParent(NULL) // "whole screen" objects. like Scenes and Layers, should set m_bIgnoreAnchorPointForPosition to true , m_nTag(kCCNodeTagInvalid) // userData is always inited as nil , m_pUserData(NULL) , m_pUserObject(NULL) , m_pShaderProgram(NULL) , m_eGLServerState(ccGLServerState(0)) , m_uOrderOfArrival(0) , m_bRunning(false) , m_bTransformDirty(true) , m_bInverseDirty(true) , m_bAdditionalTransformDirty(false) , m_bVisible(true) , m_bIgnoreAnchorPointForPosition(false) , m_bReorderChildDirty(false) , m_nScriptHandler(0) , m_nUpdateScriptHandler(0) , m_pComponentContainer(NULL) , m_bClipEnabled(false) , m_oClipRect(CCRectZero) , m_bTouchEnabled(false) , m_bTouchChildren(true) , m_drawOrder(0) , m_pScriptTouchHandlerEntry(NULL) ,_displayedOpacity(255) , _realOpacity(255) , _displayedColor(ccWHITE) , _realColor(ccWHITE) , _cascadeColorEnabled(true) , _cascadeOpacityEnabled(true) { // set default scheduler and actionManager CCDirector *director = CCDirector::sharedDirector(); m_pActionManager = director->getActionManager(); m_pActionManager->retain(); m_pScheduler = director->getScheduler(); m_pScheduler->retain(); CCScriptEngineProtocol* pEngine = CCScriptEngineManager::sharedManager()->getScriptEngine(); m_eScriptType = pEngine != NULL ? pEngine->getScriptType() : kScriptTypeNone; m_pComponentContainer = new CCComponentContainer(this); }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); pDirector->setProjection(kCCDirectorProjection2D); // set FPS. the default value is 1.0/60 if you don't call this pDirector->setAnimationInterval(1.0 / 60); // register lua engine CCLuaEngine *pEngine = CCLuaEngine::defaultEngine(); CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine); CCLuaStack *pStack = pEngine->getLuaStack(); lua_State* L = pStack->getLuaState(); luaopen_MapRuntimeC_luabinding(L); #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) // load framework // pStack->loadChunksFromZIP("res/framework_precompiled.zip"); // 如果设置了 -e 和 -ek 要加上下面这句 // pStack->setXXTEAKeyAndSign("aaa", 3); // 如果设置了 -e 和 -ek -es 则要加上下面这句 pStack->setXXTEAKeyAndSign("aaa", 3, "XT", 2); // load framework pStack->loadChunksFromZIP("res/script/framework_precompiled.zip"); pStack->loadChunksFromZIP("res/script/game.zip"); pStack->executeString("require 'main'"); // set script path //string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("scripts/main.lua"); string path = CCFileUtils::sharedFileUtils()->fullPathForFilename("scripts/main.lua"); #else // load framework if (m_projectConfig.isLoadPrecompiledFramework()) { const string precompiledFrameworkPath = SimulatorConfig::sharedDefaults()->getPrecompiledFrameworkPath(); const string precompiledGamePath = SimulatorConfig::sharedDefaults()->getPrecompiledGamePath(); pStack->setXXTEAKeyAndSign("aaa", 3, "XT", 2);//加密操作 pStack->loadChunksFromZIP(precompiledFrameworkPath.c_str()); pStack->loadChunksFromZIP(precompiledGamePath.c_str()); pStack->executeString("require 'main'"); } // set script path string path = CCFileUtils::sharedFileUtils()->fullPathForFilename(m_projectConfig.getScriptFileRealPath().c_str()); #endif size_t pos; while ((pos = path.find_first_of("\\")) != std::string::npos) { path.replace(pos, 1, "/"); } size_t p = path.find_last_of("/\\"); if (p != path.npos) { const string dir = path.substr(0, p); pStack->addSearchPath(dir.c_str()); p = dir.find_last_of("/\\"); if (p != dir.npos) { pStack->addSearchPath(dir.substr(0, p).c_str()); } } string env = "__LUA_STARTUP_FILE__=\""; env.append(path); env.append("\""); //pEngine->executeString(env.c_str()); CCLOG("==",env.c_str()); CCLOG("------------------------------------------------"); CCLOG("LOAD LUA FILE: %s", path.c_str()); CCLOG("------------------------------------------------"); //pEngine->executeScriptFile(path.c_str()); //pEngine->executeScriptFile("main.lua"); return true; }