在cocos2d-x 2.x版本中,iphone設備設置Retina高清模式已經不是原來的在高清圖後面加-hd後綴了。2.x之前開啓高清模式以後,底層會在addImage的時候自動在圖片名稱後面加-hd,優先加載-hd的圖片,沒有-hd的話,在加載原始圖。(ipad是-ipad,ipad高清是-ipadhd)。2.0.3已經移除了這個模式(好像是2.0.2就改了),2.x以後將文件管理寫成了一個共享單例類:CCFileUtils::sharedFileUtils();在加載圖片的時候,會根據圖片名稱優先在getResourceDirectory()這裏找資源,沒有的話去resource目錄下找。xcode
好比:程序開始時候,咱們設置iphone
CCFileUtils::sharedFileUtils()->setResourceDirectory(「HD」);ui
那麼全部的加載圖片都會優先在 resource/HD 這個目錄下面找,沒有的話在resource目錄找。因此在開啓Retina高清模式的時候就不能用之前的方式把高清圖加後綴-hd,而是應該在resource目錄下,新建一個目錄專門放高清圖。this
在AppDelegate中,開啓高清模式,並設置優先尋找圖片目錄爲resource/HD。spa
pDirector->enableRetinaDisplay(true);code
在2.1版本,已經去掉了手動開啓retina了,改成默認開啓。若是要使項目完美支持retina, 用setDesignResolutionSize(640, 960, kResolutionExactFit)較簡單圖片
CCFileUtils::sharedFileUtils()->setResourceDirectory(「HD」);ip
vector<string> searchPaths;
searchPaths.push_back("HD");
CCFileUtils::sharedFileUtils()->setSearchPaths(searchPaths);資源
而後把高清的圖放在resource/HD的目錄下就能夠了,不須要加後綴-hd。開發
在這裏也能夠獲取設備信息,根據不一樣設備設置不一樣的目錄。固然若是不想把高清圖放在resource也是能夠的。
好比:CCFileUtils::sharedFileUtils()->setResourceDirectory(「../HD」);
這樣HD應該是和resource處於同級目錄下。
資源文件名重複怎麼辦?
because Apple uses virtual paths, all the resources are copied to the root of this folder. So if you have multiple resources of the same name, which the setResourceDirectory method requires, when xcode deploys to the simulator it
will copy one file and then copy the second over the first. The solution is to remove the folder referenced by setResourceDirectory from the project and re-add it; but when you add the resources select: "Create folder references for any added folders".