1. 或者


其实对于我来说,最简单的屏幕适配就是使用CCEGLView::sharedOpenGLView()->setDesignResolutionSize(width,Height, kResolutionShowNoBorder);在我看来,setDesignResolutionSize()就是根据对应图片资源尺寸,也就是你设计的界面元素图片最适合的显示分辨率,按最适当的比例显示到屏幕上。这样的话,除了让其它界面元素都使用相对坐标(应该没几个会使用绝对坐标的吧……),就没多少需要做的了。


     *  Sets the array of search paths.
     *  You can use this array to modify the search path of the resources.
     *  If you want to use "themes" or search resources in the "cache", you can do it easily by adding new entries in this array.
     *  @note This method could access relative path and absolute path.
     *        If the relative path was passed to the vector, CCFileUtils will add the default resource directory before the relative path.
     *        For instance:
     *        	On Android, the default resource root path is "assets/".
     *        	If "/mnt/sdcard/" and "resources-large" were set to the search paths vector,
     *        	"resources-large" will be converted to "assets/resources-large" since it was a relative path.
     *  @param searchPaths The array contains search paths.
     *  @see fullPathForFilename(const char*)
     *  @since v2.1
// set searching paths to "/mnt/sd/example" and "/data/data/org.cocos2dx.example" 
vector<string> searchPaths;
// engine will find "1.png" in /mnt/sd/example, if there it is not found, then engine will find "1.png" in /data/data/org.cocos2dx.example
// if not found, engine will find "1.png" in Resources/ (this path is platform dependent)
CCSprite *pSprite = CCSprite::create("1.png");
  • Do not use -hd, -ipad & -ipadhd suffix(后缀) as the "file" name field in .fnt file
  • Do not use -hd, -ipad & -ipadhd suffix(后缀) as the "textureFilename" name field in .plist file
  • Do not use -hd, -ipad & -ipadhd suffix(后缀) as the "image source" name field in .tmx file
  • You should set shared resource's scale property to achieve the same display size on both Retina & Non-Retina devices, but particles are exceptional.
  • Use centralized strategy as you can