void ScreenSizeManager::DoInitFixedScreenSize(float myScreenWidth,
                                              float myScreenHeight)
{
    _isInit = true;
    // cocos2d-x v3.0.0 이상만 지원.
    CCAssert(0x00030000 <= COCOS2D_VERSION, "ScreenSizeManager need to cocos2d-x 3.0.0 or higher!");
    
    Director* kDirector = CCDirector::getInstance();
    
    CCAssert(kDirector->getOpenGLView(), "ScreenSizeManager need to kDirector->getOpenGLView() is not NULL");
    
    Size kWinSize = kDirector->getWinSize();
    
    _screenSize.width = kWinSize.width;
    _screenSize.height = kWinSize.height;
    
    _imageResolutionSize.width = myScreenWidth;
    _imageResolutionSize.height = myScreenHeight;
    
    log("DoInitFixedScreenSizeManager %f %f", _imageResolutionSize.width, _imageResolutionSize.height);
    
    // Cocos2d상의 포인트영역이 _imageResolutionSize.width, _imageResolutionSize.height 으로 설정된다.
    // CCDirector::sharedDirector()->getWinSize()의 width, height 가 _imageResolutionSize.width, _imageResolutionSize.height 로 된다.
    
    ResolutionPolicy kResolutionPolicy = ResolutionPolicy::NO_BORDER;
    
    GLView* kGLView = kDirector->getOpenGLView();
    kGLView->setDesignResolutionSize(_imageResolutionSize.width, _imageResolutionSize.height, kResolutionPolicy);
    
    
}
void ScreenSizeManager::DoInitFlexibleScreenSize(float myImageResolutionWidth,
                                                 float myImageResolutionHeight)
{
    _isInit = true;
    // cocos2d-x v3.0.0 이상만 지원.
    CCAssert(0x00030000 <= COCOS2D_VERSION, "ScreenSizeManager need to cocos2d-x 3.0.0 or higher!");
    
    Director* kDirector = Director::getInstance();
    
    CCAssert(kDirector->getOpenGLView(), "ScreenSizeManager need to kDirector->getOpenGLView() is not NULL");
    
    Size kWinSize = kDirector->getWinSize();
    
    _screenSize.width = kWinSize.width;
    _screenSize.height = kWinSize.height;
    
    _imageResolutionSize.width = myImageResolutionWidth;
    _imageResolutionSize.height = myImageResolutionHeight;
    
    float kDefaultDesignResRatio = _imageResolutionSize.width / _imageResolutionSize.height;
    float kScreenRatio = _screenSize.width / _screenSize.height;
    
    if ( kDefaultDesignResRatio <= kScreenRatio)
    {
        float kHeightRatio = _screenSize.height  / _imageResolutionSize.height;
        // 폭이 넓은 경우
        _imageResolutionSize.width = (int)(_screenSize.width / kHeightRatio);
        _isScaleHeight = true;
    }
    else
    {
        // 높이가 긴 경우
        float kWidthRatio = _screenSize.width / _imageResolutionSize.width;
        // 폭이 넓은 경우
        _imageResolutionSize.height = (int)(_screenSize.height  / kWidthRatio);
        _isScaleHeight = false;
    }
    
    log("DoInitResourceSizeScreen %f %f", _imageResolutionSize.width, _imageResolutionSize.height);
    
    // Cocos2d상의 포인트영역이 _imageResolutionSize.width, _imageResolutionSize.height 으로 설정된다.
    // CCDirector::sharedDirector()->getWinSize()의 width, height 가 _imageResolutionSize.width, _imageResolutionSize.height 로 된다.
    ResolutionPolicy kResolutionPolicy = ResolutionPolicy::NO_BORDER;
   
    GLView* kGLView = kDirector->getOpenGLView();
    kGLView->setDesignResolutionSize(_imageResolutionSize.width, _imageResolutionSize.height, kResolutionPolicy);
  
    
}
bool WelcomeMenu::init()
{
    if(!Layer::init())
    {
    return false;
    }
    GLView* glView      = Director::getInstance()->getOpenGLView();
    enum ResolutionPolicy policy = ResolutionPolicy::SHOW_ALL;
    glView->setDesignResolutionSize(960, 640, policy);
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin     = Director::getInstance()->getVisibleOrigin();
    auto menu = this->_createMenu();
    menu->setPosition(480, 320);
    this->addChild(menu);
    return true;
}
示例#4
0
bool ScreenTest::init()
{
    // 物理分辨率
    GLView *glview = Director::getInstance()->getOpenGLView();
    Size frameSize = glview->getFrameSize();
    
    CCLOG("FRAME SIZE: %dx%d", (int)frameSize.width, (int)frameSize.height);
    // Result:
    // iPhone(3.5-inch)         960x640             1.5
    // iPhone(4-inch)           1136x640            1.775
    // iPad                     1024x768            1.333
    // iPad Retina              2048x1536           1.333
    
    // 设置逻辑上的游戏屏幕大小
    // ResolutionPolicy::EXACT_FIT为了保持了全屏显示,对画面进行了拉伸(不推荐!)
    //    glview->setDesignResolutionSize(400, 480, ResolutionPolicy::EXACT_FIT);
    
    // ResolutionPolicy::SHOW_ALL为了保持设计画面比例对四周进行留黑边处理,使得不同比例下画面不能全屏。
    //    glview->setDesignResolutionSize(400, 480, ResolutionPolicy::SHOW_ALL);
    
    // ResolutionPolicy::NO_BORDER为了填补留下的黑边,将画面稍微放大,以至于能够正好补齐黑边
    glview->setDesignResolutionSize(m_designWidth, m_designHeight, ResolutionPolicy::NO_BORDER);
    // 其他参数,参考ResolutionPolicy的注释
    
    Size winSize = Director::getInstance()->getWinSize();
    CCLOG("WIN SIZE: %dx%d", (int)winSize.width, (int)winSize.height);
    // Result: winSize的大小为glview->setDesignResolutionSize()设置的值
    // 默认为FrameSize
    
    
    

    
    auto dispatcher = Director::getInstance()->getEventDispatcher();
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    // Add Touch Listener
    auto touchListener = EventListenerTouchAllAtOnce::create();
    touchListener->onTouchesBegan = CC_CALLBACK_2(ScreenTest::onTouchesBegan, this);
    touchListener->onTouchesMoved = CC_CALLBACK_2(ScreenTest::onTouchesMoved, this);
    touchListener->onTouchesEnded = CC_CALLBACK_2(ScreenTest::onTouchesEnded, this);
    touchListener->onTouchesCancelled = CC_CALLBACK_2(ScreenTest::onTouchesCancelled, this);
    dispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
    
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
    
    // Add Mouse Listener
    auto mouseListener = EventListenerMouse::create();
//    mouseListener->onMouseMove = CC_CALLBACK_1(ScreenTest::onMouseMove, this);
//    mouseListener->onMouseUp = CC_CALLBACK_1(ScreenTest::onMouseUp, this);
//    mouseListener->onMouseDown = CC_CALLBACK_1(ScreenTest::onMouseDown, this);
    mouseListener->onMouseScroll = CC_CALLBACK_1(ScreenTest::onMouseScroll, this);
    dispatcher->addEventListenerWithSceneGraphPriority(mouseListener, this);
#endif
    
    m_editWidth = UIUtil::createEditBox(this, 100, 160, "Design Width");
    m_editHeight = UIUtil::createEditBox(this, 100, 100, "Design Height");
    
    m_editHeight->setInputMode(EditBox::InputMode::NUMERIC);
    m_editWidth->setInputMode(EditBox::InputMode::NUMERIC);
    
    char width[32];
    sprintf(width, "%d", (int)winSize.width);
    m_editWidth->setText(width);
    
    char height[32];
    sprintf(height, "%d", (int)winSize.height);
    m_editHeight->setText(height);

    return true;
}
示例#5
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    Director* pDirector = gDirector;
    
    GLView* pGLView = pDirector->getOpenGLView();
    if( NULL == pGLView )
    {
        pGLView = GLView::create("game(v1.0.0.0)---test for inner");
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
        pGLView->setFrameSize(1334, 750);
#endif
        
        pDirector->setOpenGLView(pGLView);
    }
    
    // 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);
    
    // resolution information  
    Size size;  
    size= pDirector->getWinSize();
	log("***IDONG: Director getWinSize:w=%f,h=%f",size.width,size.height);  

	size = pDirector->getWinSizeInPixels();  
	log("***IDONG: Director getWinSizeInPixels:w=%f,h=%f",size.width,size.height);  

	size = pDirector->getVisibleSize();  
	log("***IDONG: Director getVisibleSize:w=%f,h=%f",size.width,size.height);  

	Point point = pDirector->getVisibleOrigin();  
	log("***IDONG: Director getVisibleOrigin:x=%f,y=%f",point.x,point.y);  


	log("***IDONG: Director BS: getContentScaleFactor: scaleFactor=%f",pDirector->getContentScaleFactor());  

	auto framsize = pGLView->getFrameSize();
	auto dwinsize = pDirector->getWinSize();
	auto designsize = Size(SCREEN_WIDTH, SCREEN_HEIGHT);
	auto widthRate = framsize.width/designsize.width;
	auto heightRate = framsize.height/designsize.height;

	auto  resolutionRate = 1.f;
	if(widthRate > heightRate) 
	{
		pGLView->setDesignResolutionSize(designsize.width,
		 designsize.height*heightRate/widthRate, ResolutionPolicy::NO_BORDER);
		 resolutionRate = heightRate/widthRate;
	}
	else
	{
		pGLView->setDesignResolutionSize(designsize.width*widthRate/heightRate, designsize.height,
		 ResolutionPolicy::NO_BORDER);
		 resolutionRate = widthRate/heightRate;
	}

	//pGLView->setDesignResolutionSize(SCREEN_WIDTH, SCREEN_HEIGHT, ResolutionPolicy::FIXED_HEIGHT);

	log("***IDONG:/n");  
	log("***IDONG: Director AS: getContentScaleFactor: scaleFactor=%f",pDirector->getContentScaleFactor());  

	size= pDirector->getWinSize();  
	log("***IDONG: Director getWinSize:w=%f,h=%f",size.width,size.height);  

	size = pDirector->getWinSizeInPixels();  
	log("***IDONG: Director getWinSizeInPixels:w=%f,h=%f",size.width,size.height);  

	size = pDirector->getVisibleSize();  
	log("***IDONG: Director getVisibleSize:w=%f,h=%f",size.width,size.height);  

	point = pDirector->getVisibleOrigin();  
	log("***IDONG: Director getVisibleOrigin:x=%f,y=%f",point.x,point.y);  

	// ‘ˆº”À—À˜¬∑æ∂
	gFileUtils->addSearchPath("assets");

	// …Ë÷√◊ ‘¥ƒø¬�?
	// ≥ı ºªØ◊ ‘¥ƒø¬�?dumpŒƒº˛…˙≥…ƒø¬�?
	string logfile = "";
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	gGameManager->SetResourceRoot("/mnt/sdcard/com.zm.mszb/");
	gGameManager->CreateDirectory(gGameManager->GetResourceRoot());
	gGameManager->CreateDirectory(gGameManager->GetLogPath());
	logfile = gGameManager->GetLogPath()+"/log.txt";
	gLog->Open(logfile.c_str());
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
	gGameManager->SetResourceRoot("");
	gGameManager->CreateDirectory(gGameManager->GetResourceRoot());
	gGameManager->CreateDirectory(gGameManager->GetLogPath());
	logfile = gGameManager->GetLogPath()+"/log.txt";
	gLog->Open(logfile.c_str());
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
	gGameManager->SetResourceRoot(gFileUtils->getWritablePath());
	gGameManager->CreateDirectory(gGameManager->GetResourceRoot());
	gGameManager->CreateDirectory(gGameManager->GetLogPath());
	logfile = gGameManager->GetLogPath()+"/log.txt";
	gLog->Open(logfile.c_str());
#endif
	gGameManager->LogMachineInfo();
	// ø™ º∏¸–�?
	gGameManager->Start();

    return true;
}