coco2dx 2.0 解决 android多分辨率问题

cocos2dx 跨平台引擎真的很有意思,我最近决定把oc写的游戏转到cocos2dx上面来

不过androd平台上多分辨率是个大问题,ios的没所谓,480*320  960*640  1024*768  2048*1536  基于像素点都能很好的解决

还好,cocos2dx上提供setDesignResolutionSize 支持多分辨率,不过使用后就知道了,如果不是480*320 屏幕比的话,会出现黑边

我的g7就是800*480  所以运行helloword的时候会出现两边有黑边

解决方案:

结合google上的资料:

原理:同样采取setDesignResolutionSize 像素点原则  只是稍微调整某些地方

在main.app里面  把:

 

把
view->setDesignResolutionSize(viewWidth, 320);
改为:
        float scaleH = (float)h/320;
        int viewWidth = (int)(w/scaleH);
        view->setDesignResolutionSize(viewWidth, 320);

原理:以高度 320像素点为原则  width 采用高度同样的比例换算成相应的逻辑点

480/320= 1.5  就是说:一个逻辑点等于1.5个像素点

所以800 换算成逻辑点是:533

然后HelloWorldScene.cpp 的背景要修改一下  hellword.png 为480*320  

改为:

 // add "HelloWorld" splash screen"
    CCSprite* pSprite = CCSprite::create("HelloWorld.png");

    // position the sprite on the center of the screen
    int bg_size_w = pSprite->getTexture()->getContentSize().width;
    int bg_size_h = pSprite->getTexture()->getContentSize().height;
    CCLog("bg_size_w %d",bg_size_w);
    float f_w = size.width/(float)bg_size_w;
    float f_h = size.height/(float)bg_size_h;
    pSprite->setScaleX(f_w);
    pSprite->setScaleY(f_h)

然后 Cygwin biuld 下 build_native.sh  

eclipse生成apk 运行 yeah  解决了分辨率的问题

posted @ 2012-07-26 14:17  dodohua  阅读(1532)  评论(0编辑  收藏  举报