原址为:http://www.ityran.com/archives/2911?cb=016555509017780423,好东西必须得收藏。
目前的一些基本认识,以后有更深的理解再加以补充。欢迎指出错误,共同进步。
AppDelegate类里
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
CCDirector* pDirector = CCDirector::sharedDirector();
CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
pDirector->setOpenGLView(pEGLView);
pEGLView->setDesignResolutionSize(480, 320, kResolutionShowAll);
// 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);
// create a scene. it's an autorelease object
CCScene *pScene = HelloWorld::scene();
// run
pDirector->runWithScene(pScene);
return true;
}
相对于最初始化的代码,只添加了pEGLView->setDesignResolutionSize(480, 320, kResolutionShowAll);这一句,这里说明开发者设置的屏幕逻辑大小分辨率为480*320。这里的参数大小一般设置为背景图的大小。
main函数
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// create the application instance
AppDelegate app;
CCEGLView* eglView = CCEGLView::sharedOpenGLView();
eglView->setViewName("ProgressTest");
eglView->setFrameSize(480, 320);
return CCApplication::sharedApplication()->run();
}
其中eglView->setFrameSize(480, 320);设置了当前屏幕分辨率为480*320.通过设置setFrameSize函数和,setDesignResolutionSize函数传递数值过去,就可以得到VisibleSize和VisibleOrigin(通过vs在这两个函数上点击查看自定义貌似是这样的,不知道我又没有理解错呢。。。求指出。)
VisibleSize和VisibleOrigin
getVisibleSize:表示获得视口(可视区域)的大小,如果DesignResolutionSize跟屏幕尺寸一样大,则getVisibleSize等于getWinSize。
getVisibleOrigin:表示可视区域的起点坐标,这在处理相对位置的时候非常有用,确保节点在不同分辨率下的位置一致。
其实,感觉上在 AppDelegate::applicationDidFinishLaunching()这个函数里调用pEGLView->setDesignResolutionSize(480, 320, kResolutionShowAll);就可以实现简单的屏幕适配了。至于第三个参数的理解以及更好的了解,强求希望你看上面那个网址。
好了,以后有新的理解在进行补充。