本文整理汇总了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);
}
示例2: menuCloseCallback
void ModalLayer::menuCloseCallback(CCObject* pSender)
{
this->removeFromParentAndCleanup(true);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->removeDelegate(this);
}
示例3: onOK
void HUILayer::onOK() {
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->end();
}
示例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)
//.........这里部分代码省略.........
示例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;
}
示例6: registerStandardDelegate
void JSTouchDelegate::registerStandardDelegate() {
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addStandardDelegate(this,0);
}
示例7: northPoleSceneCallback
void MainMenu::northPoleSceneCallback(CCObject* pSender){
CCDirector *director = CCDirector::sharedDirector();
director->replaceScene(FarmScene::farmScene());
}
示例8: onEnter
void HelloWorld::onEnter(){
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
}
示例9: registerWithTouchDispatcher
void CCLayer::registerWithTouchDispatcher()
{
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addStandardDelegate(this, 0);
}
示例10: registerWithTouchDispatcher
void TaskChatLayer::registerWithTouchDispatcher()
{
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, kCCScrollTouchBgPriority, true);
}
示例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);
//.........这里部分代码省略.........
示例12: registerWithTouchDispatcher
void Menu::registerWithTouchDispatcher()
{
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, kCCMenuHandlerPriority + 1, true);
}
示例13: registerWithTouchDispatcher
void KeyboardNotificationLayer::registerWithTouchDispatcher()
{
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, false);
}
示例14: onExit
void GameObjHero::onExit()
{
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->removeDelegate(this);
CCNode::onExit();
}
示例15: onExit
void HelloWorld::onExit(){
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->removeDelegate(this);
}