cocos2dx 屏幕分辨率问题

做手机上的软件首先要考虑的就是屏幕分辨率怎么解决.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);

效果如下:

 

posted @ 2013-12-31 20:00  onlycxue  阅读(3597)  评论(0编辑  收藏  举报