当前位置: 首页>>代码示例>>C++>>正文


C++ CCDirector类代码示例

本文整理汇总了C++中CCDirector的典型用法代码示例。如果您正苦于以下问题:C++ CCDirector类的具体用法?C++ CCDirector怎么用?C++ CCDirector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CCDirector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: preInitAPI

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);
        }
开发者ID:kun-g,项目名称:client,代码行数:88,代码来源:AppDelegate.cpp

示例2: menuCloseCallback

void ModalLayer::menuCloseCallback(CCObject* pSender)
{
    this->removeFromParentAndCleanup(true);
    CCDirector* pDirector = CCDirector::sharedDirector();
    pDirector->getTouchDispatcher()->removeDelegate(this);
}
开发者ID:Tetz,项目名称:cocos2dx_demo,代码行数:6,代码来源:ModalLayer.cpp

示例3: onOK

void HUILayer::onOK() {
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->end();
}
开发者ID:hyizsg,项目名称:mytest1st,代码行数:4,代码来源:UILayer.cpp

示例4: CCSizeMake

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)
//.........这里部分代码省略.........
开发者ID:guozanhua,项目名称:project-birds,代码行数:101,代码来源:AppDelegate.cpp

示例5: applicationDidFinishLaunching

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;
}
开发者ID:JerryLootsie,项目名称:BTEndlessTunnel,代码行数:66,代码来源:AppDelegate.cpp

示例6: registerStandardDelegate

void JSTouchDelegate::registerStandardDelegate() {
    CCDirector* pDirector = CCDirector::sharedDirector();
    pDirector->getTouchDispatcher()->addStandardDelegate(this,0);
}
开发者ID:dumganhar,项目名称:HelloExtensionJS,代码行数:4,代码来源:cocos2d_specifics.cpp

示例7: northPoleSceneCallback

void MainMenu::northPoleSceneCallback(CCObject* pSender){
    CCDirector *director = CCDirector::sharedDirector();
    director->replaceScene(FarmScene::farmScene());
}
开发者ID:shaneycku,项目名称:ToddlerGame,代码行数:4,代码来源:MainMenu.cpp

示例8: onEnter

void HelloWorld::onEnter(){
    CCDirector* pDirector = CCDirector::sharedDirector();
    pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true);

}
开发者ID:dkgrayson,项目名称:BrickBreaker,代码行数:5,代码来源:HelloWorldScene.cpp

示例9: registerWithTouchDispatcher

void CCLayer::registerWithTouchDispatcher()
{
    CCDirector *pDirector = CCDirector::sharedDirector();

    pDirector->getTouchDispatcher()->addStandardDelegate(this, 0);
}
开发者ID:Ivory27,项目名称:LoomSDK,代码行数:6,代码来源:CCLayer.cpp

示例10: registerWithTouchDispatcher

void TaskChatLayer::registerWithTouchDispatcher()
{
	CCDirector* pDirector = CCDirector::sharedDirector();
	pDirector->getTouchDispatcher()->addTargetedDelegate(this, kCCScrollTouchBgPriority, true);
}
开发者ID:niuzb,项目名称:hellopetclient,代码行数:5,代码来源:TaskChatLayer.cpp

示例11: CCSizeMake

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);
//.........这里部分代码省略.........
开发者ID:yohyow,项目名称:cocos2dxTest,代码行数:101,代码来源:AppDelegate.cpp

示例12: registerWithTouchDispatcher

void Menu::registerWithTouchDispatcher()
{
    CCDirector* pDirector = CCDirector::sharedDirector();
    pDirector->getTouchDispatcher()->addTargetedDelegate(this, kCCMenuHandlerPriority + 1, true);
}
开发者ID:jonesgithub,项目名称:LinkLiner,代码行数:5,代码来源:MenuScene.cpp

示例13: registerWithTouchDispatcher

void KeyboardNotificationLayer::registerWithTouchDispatcher()
{
		CCDirector* pDirector = CCDirector::sharedDirector();
		pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, false);
}
开发者ID:Whislly,项目名称:DreamBookToolbox,代码行数:5,代码来源:KeyboardNotificationLayer.cpp

示例14: onExit

void GameObjHero::onExit()
{
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->getTouchDispatcher()->removeDelegate(this);
    CCNode::onExit();
}
开发者ID:pandazheng,项目名称:LuoLiRunGame,代码行数:6,代码来源:GameObjHero.cpp

示例15: onExit

void HelloWorld::onExit(){
    CCDirector* pDirector = CCDirector::sharedDirector();
    pDirector->getTouchDispatcher()->removeDelegate(this);
}
开发者ID:dkgrayson,项目名称:BrickBreaker,代码行数:4,代码来源:HelloWorldScene.cpp


注:本文中的CCDirector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。