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);
  
    
}
Exemplo n.º 3
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
	Director* director = Director::getInstance();
	GLView* glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("My Game");
        director->setOpenGLView(glview);
    }

    // turn on display FPS
    director->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);

    register_all_packages();

    // create a scene. it's an autorelease object
    Scene* scene = WelcomeScene::scene();

    // run
    director->runWithScene(scene);

    SimpleAudioEngine::getInstance()->preloadBackgroundMusic("sounds/BgmCity.mp3");
    SimpleAudioEngine::getInstance()->playBackgroundMusic("sounds/BgmCity.mp3",true);
    return true;
}
Exemplo n.º 4
0
void WelcomeMenu::_startGameMenuCallback(Ref* pSender)
{
    Director* director = Director::getInstance();
    GLView*   glView   = director->getOpenGLView();
    Size frameSize      = glView->getFrameSize();
    Size winSize       = director->getWinSize();
    log("winSize %f=%f ",winSize.width, winSize.height );
    log("frameSize %f=%f", frameSize.width, frameSize.height);
}
            void WebViewImpl::draw(Renderer *renderer, Mat4 const &transform, uint32_t flags)
            {
                if (_createSucceeded && (flags & Node::FLAGS_TRANSFORM_DIRTY))
                {
                    Director *directorInstance = cocos2d::Director::getInstance();
                    GLView *glView = directorInstance->getOpenGLView();
                    const Size &frameSize = glView->getFrameSize();
                    const Size &winSize = directorInstance->getWinSize();
                    Vec2 leftBottom = this->_webView->convertToWorldSpace(Point::ZERO);
                    Vec2 rightTop = this->_webView->convertToWorldSpace(Point(_webView->getContentSize().width, _webView->getContentSize().height));
                    float uiLeft = frameSize.width / 2 + (leftBottom.x - winSize.width / 2) * glView->getScaleX();
                    float uiTop = frameSize.height / 2 - (rightTop.y - winSize.height / 2) * glView->getScaleY();

                    _systemWebControl->setWebViewRect(uiLeft, uiTop,
                        (rightTop.x - leftBottom.x) * glView->getScaleX(),
                        (rightTop.y - leftBottom.y) * glView->getScaleY());
                }
            }
Exemplo n.º 6
0
void TextureManager::clear() {
    Director *director = Director::getInstance();
    auto glView = director->getOpenGLView();
    auto renderer = director->getRenderer();

    long long start = currentTimeMillis();
    CCLOG("texMgr clear texModuleCount=%d", texModuleMap.size());
    renderer->render();
    CCLOG("render before success");

    int textureCosts[TEXTURE_COUNT] = {0};

    int curLoopCounter = Director::loopCounter;

    for(auto& entry : texModuleMap) {
        auto tm = entry.second;

        for(int i = 0; i < TEXTURE_COUNT; ++i) {
            if(textures[i] == tm->tex) {
                textureCosts[i] += (tm->lastCallCounter - curLoopCounter) * tm->width * tm->height;
                break;
            }
        }
    }

    int min = INT_MAX;
    int index = -1;

    for(int i = 0; i < TEXTURE_COUNT; ++i) {
        CCLOG("textureCosts[%d]=%d", i, textureCosts[i]);

        if(min > textureCosts[i]) {
            min = textureCosts[i];
            index = i;
        }
    }

    int length = TEXTURE_SIZE * TEXTURE_SIZE << 2;
    byte *data = new byte[length];
    memset(data, 0, length);
    textures[index]->initWithData(data, length, Texture2D::PixelFormat::RGBA8888, TEXTURE_SIZE, TEXTURE_SIZE, Size(TEXTURE_SIZE, TEXTURE_SIZE));
    textureBins[index]->init(TEXTURE_SIZE, TEXTURE_SIZE);

    std::vector<int> toDeletes;

    for(auto& entry : texModuleMap) {
        auto tm = entry.second;

        if(tm->tex == textures[index]) {
            CC_SAFE_DELETE(tm);
            toDeletes.push_back(entry.first);
        }
    }

    for(auto id : toDeletes) {
        texModuleMap.erase(id);
    }

	toDeletes.clear();

	for (auto& entry : texCoordCalculatedMap) {
		auto tex = entry.second;
		if (tex == textures[index]) {
			toDeletes.push_back(entry.first);
		}
	}

	for (auto id : toDeletes) {
		texCoordCalculatedMap.erase(id);
	}

    CC_SAFE_DELETE_ARRAY(data);
    CCLOG("after texMgr clear texModuleCount=%d, clearTexId=%d, recalculate count %d, cost Time=%lld", texModuleMap.size(), index, toDeletes.size(), currentTimeMillis() - start);
}
Exemplo n.º 7
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;
}