做手機上的軟件首先要考慮的就是屏幕分辨率怎么解決.coco2dx已經有了很好的解決方法.
用cocos2dx的python腳本創建工程時默認生成一個Helloworld的demo.我們就以這個demo說事.這個demo的在ubuntu的運行的結果如下:
在這種情況下屏幕顯示設置為480x320 圖片的分辨率正好也是480x320
main.cpp如下:
-MiniBufExplorer- 1,1 All 1 #include "../Classes/AppDelegate.h" 2 #include "cocos2d.h" 3 #include "CCEGLView.h" 4 5 #include <stdlib.h> 6 #include <stdio.h> 7 #include <unistd.h> 8 #include <string> 9 10 USING_NS_CC; 11 12 int main(int argc, char **argv) 13 { 14 // create the application instance 15 AppDelegate app; 16 CCEGLView* eglView = CCEGLView::sharedOpenGLView(); 17 eglView->setFrameSize(480,320); 18 return CCApplication::sharedApplication()->run(); 19 }
當把eglView->setFrameSize(480,320);改為 eglView->setFrameSize(960,640)時
結果如下:
由於圖片的分辨率和屏幕的分辨率不符合所以圖片四周有黑邊.這種情況下又兩種解決方法.一種是在准備一套圖片,另一種方法就是讓圖片拉伸,現在主要說讓圖片拉伸.
只要添加一句話在AppDelegate.cpp 的applicationDidFinishLaunching()函數中
pEGLView->setDesignResolutionSize(480,320,kResolutionNoBorder);
效果如下: