前端之家收集整理的这篇文章主要介绍了
我的COCOS2D-X 3.0适配方案,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if (!glview) {
glview = GLView::createWithRect("js-tests",Rect(0,900,640));
director->setOpenGLView(glview);
}
CCSize frameSize = glview->getFrameSize();
CCSize winSize = CCSize(960,640);
float scalex = frameSize.width / winSize.width;
float scaley = frameSize.width / winSize.height;
if (scalex > scaley)
{
glview->setDesignResolutionSize(winSize.width*scalex / scaley,winSize.height,ResolutionPolicy::NO_BORDER);
}
else
{
glview->setDesignResolutionSize(winSize.width,winSize.height*scaley / scalex,ResolutionPolicy::NO_BORDER);
}