接下来我们再做些坏事,比如给EGLView设置分辨率,代码如下:
- pEGLView->setDesignResolutionSize(240, 320, kResolutionExactFit);
- CCSize size;
- size = pDirector->getWinSize();
- CCLOG("width = %f height = %f, pDirector->getWinSize", size.width, size.height);
- size = pDirector->getWinSizeInPixels();
- CCLOG("width = %f height = %f, pDirector->getWinSizeInPixels", size.width, size.height);
- size = pDirector->getVisibleSize();
- CCLOG("width = %f height = %f, pDirector->getVisibleSize", size.width, size.height);
- size = pEGLView->getFrameSize();
- CCLOG("width = %f height = %f, pEGLView->getFrameSize", size.width, size.height);
- size = pEGLView->getDesignResolutionSize();
- CCLOG("width = %f height = %f, pEGLView->getDesignResolutionSize", size.width, size.height);
- size = pEGLView->getVisibleSize();
- CCLOG("width = %f height = %f, pEGLView->getVisibleSize", size.width, size.height);
这个效果是将图片做了一个拉伸,再显示在屏幕上,那么调试信息是如何的?
我们可以看到,pEGLView->getFrameSize不受影响,其他都变化了,为什么getFrameSize那么特殊?查看cocos2dx源代码发现,getFrameSize返回的是成员变量m_obScreenSize,而这个值在通过setFrameSize赋值之后就不会再更改了,这个值描述的是窗口在屏幕像素单位的大小,再直白点就是窗口的尺寸。
而其他的尺寸,都是依赖于程序员设置的分辨率,因为我们人为的设置了分辨率,所以其他尺寸函数返回的都是自定义的分辨率。
-------------------------------------------------------------------------------------------------------------------------------华丽的分割线
那现在我们再修改下代码,将设置分辨率的方法修改下:
- pEGLView->setDesignResolutionSize(240, 320, kResolutionNoBorder);
- CCSize size;
- size = pDirector->getWinSize();
- CCLOG("width = %f height = %f, pDirector->getWinSize", size.width, size.height);
- size = pDirector->getWinSizeInPixels();
- CCLOG("width = %f height = %f, pDirector->getWinSizeInPixels", size.width, size.height);
- size = pDirector->getVisibleSize();
- CCLOG("width = %f height = %f, pDirector->getVisibleSize", size.width, size.height);
- size = pEGLView->getFrameSize();
- CCLOG("width = %f height = %f, pEGLView->getFrameSize", size.width, size.height);
- size = pEGLView->getDesignResolutionSize();
- CCLOG("width = %f height = %f, pEGLView->getDesignResolutionSize", size.width, size.height);
- size = pEGLView->getVisibleSize();
- CCLOG("width = %f height = %f, pEGLView->getVisibleSize", size.width, size.height);
- CCPoint pt = pEGLView->getVisibleOrigin();
- CCLOG("originX=%f, originY=%f", pt.x, pt.y);
修改成kResolutionNoBorder形式,并且把EGLView的origin坐标打印出来
打印结果如下:
这里我们可以看到,getVisibleSize有变化了,程序运行的结果,的确是没有显示所有的内容,只是显示了部分内容:
EGLView的origin坐标,之前都是0,0,现在也有了变化,变成0,80了
这个原因是因为用NoBorder属性之后,窗口就不作为border了,内容可以伸展到窗口之外,这样窗口可能就只显示了一部分,那么可见范围自然就小了
origin坐标是窗口原点在内容坐标系中的坐标。