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