泰然 cocos2d-x多分辨率适配方案

原址为: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);就可以实现简单的屏幕适配了。至于第三个参数的理解以及更好的了解,强求希望你看上面那个网址。

好了,以后有新的理解在进行补充。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值