bSceneCutsomResolution决定适配策略ResolutionPolicy::EXACT_FIT会用缩放拉伸的方式适配
void CAutoScreen::SetSceneResolute(float w, float h, bool bSceneCutsomResolution)
{
CAutoScreen::sceneCutsomResolution=bSceneCutsomResolution;
if(bSceneCutsomResolution)
{
cocos2d::Size ls = Size(w, h);
Size fs = Director::getInstance()->getOpenGLView()->getFrameSize();
float sx = ls.width/fs.width;
float sy = ls.height/fs.height;
sceneResolute = ls;
//定义 scale 变量
resoluteBool = sx>sy;
float scale = resoluteBool?sx:sy;
SetSceneSize(resoluteBool?ls.width:fs.width*scale, resoluteBool?fs.height*scale:ls.height);
SetSceneScale(resoluteBool?fs.height*scale/ls.height : fs.width*scale/ls.width);
Director::getInstance()->getOpenGLView()->setDesignResolutionSize(GetSceneWidth(), GetSceneHeight(), ResolutionPolicy::SHOW_ALL);
}
else
{
sceneScale = 0.0f;
sceneSize = Size(w, h);
sceneResolute = Size(w, h);
Director::getInstance()->getOpenGLView()->setDesignResolutionSize(w, h, ResolutionPolicy::EXACT_FIT);
}
Director::getInstance()->setContentScaleFactor(1.0f);
}