coco2dx 2.0 解決 android多解析度問題

來源:互聯網
上載者:User

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  解決了解析度的問題

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.