_screenSize glview->getFrameSize 真实设备分辨率
_designResolutionSize 设计的分辨率 ,注意director里的这个winsize和screenSize不一样
director->_winSizeInPoints =getDesignResolutionSize(); 是update DesignSize之后的DesignSize
用在Scene this->setContentSize(director->getWinSize());
_viewPortRect 视口大小,大部分情况跟ScreenSize差不多大,跟libgdx里designSize就跟viewport Size差不多大小不一样
glview->setDesignResolutionSize(800, 480,ResolutionPolicy::EXACT_FIT);
800*480,原型分辨率宽高,游戏开发以这个分辨率作为设计时的场景像素
1.EXACT_FIT,不保持高宽比,拉伸高或宽,全屏显示,以适应设备屏幕
2.NO_BORDER,保持高宽比,高宽按比率拉伸,目标场景比屏幕大,这样有一边显示不全,且居中显示
3.SHOW_ALL,保持高宽比,跟NO_BORDER类似,但比屏幕小,有一边保持跟屏幕一样,另一边居中显示
4.FIXED_HEIGHT,改变designSize,固定高,拉伸宽,使得跟设备高宽比一样,最后再全屏显示。
这样目标场景就不是800*480了,可能变成854*480,用这个得考虑游戏布局是否适应不同的高宽比
5.FIXED_WIDTH,固定宽,拉伸高,使得跟设备高宽比一样,最后再全屏显示
VisibleSize CCGLViewProtocol.cpp designSize的可见大小,大部分等于designSize
Size GLViewProtocol::getVisibleSize()const
{
if (_resolutionPolicy ==ResolutionPolicy::NO_BORDER)
{
returnSize(_screenSize.width/_scaleX,_screenSize.height/_scaleY); //不管在屏幕外显示的部分
}
else
{
return_designResolutionSize; //其他的跟designSize一样大,注意FIXED_WIDTH跟FIXED_HEIGHT把designSize改变了
}
}
Vec2 GLViewProtocol::getVisibleOrigin()const
{
if (_resolutionPolicy ==ResolutionPolicy::NO_BORDER)
{
returnVec2((_designResolutionSize.width -_screenSize.width/_scaleX)/2,
(_designResolutionSize.height -_screenSize.height/_scaleY)/2); //居中显示
}
else
{
return Vec2::ZERO;
}
}
getViewPortRect _viewPortRect designSize拉伸后的size ,大部分等于ScreenSize
_scaleX = (float)_screenSize.width /_designResolutionSize.width;
_scaleY = (float)_screenSize.height /_designResolutionSize.height;
if (_resolutionPolicy ==ResolutionPolicy::NO_BORDER)
{
_scaleX = _scaleY = MAX(_scaleX,_scaleY);
}
elseif (_resolutionPolicy ==ResolutionPolicy::SHOW_ALL)
{
_scaleX = _scaleY = MIN(_scaleX,_scaleY);
}
elseif (_resolutionPolicy ==ResolutionPolicy::FIXED_HEIGHT) {
_scaleX = _scaleY;
_designResolutionSize.width =ceilf(_screenSize.width/_scaleX);
}
elseif (_resolutionPolicy ==ResolutionPolicy::FIXED_WIDTH) {
_scaleY = _scaleX;
_designResolutionSize.height =ceilf(_screenSize.height/_scaleY);
}
// calculate the rect of viewport
float viewPortW =_designResolutionSize.width *_scaleX;
float viewPortH =_designResolutionSize.height *_scaleY;
_viewPortRect.setRect((_screenSize.width - viewPortW) /2, (_screenSize.height - viewPortH) /2, viewPortW, viewPortH);