cocos2d-x 2.0.4 resource pathes questions


Hi guys,

First, thanks for your amazing work. I’ve switched from cocos2d-iphone to cocos2d-x pretty easily, API is almost the same and easy to learn. I’m developing an iOS game now which should be working on all devices so I’ve decided to integrate CocosBuilder and all the best practices for handling multiple resolutions from start, not to worry about it in the end.

The main problem I’ve encountered is that I can’t understand how should I reference to resources from code and how should I structure my folders. I’ve created “ipad” and “iphone” folders inside my Resources folder, in which I keep atlases and fonts specific to those resolutions. I set those directories for FileUtils according to the resolution. Also I have a “CocosBuilder” folder in the Resources. All the folders are linked as “blue” folders in XCode, not groups. CocosBuilder’s project takes the images from “iphone” folder when designing menus. I guess there’s something wrong with it but I don’t get what yet.

Application crashes instantly, because I start with the scene created from ccbi file and readNodeGraphFromFile returns nil. After that I’ve changed createSceneWithNodeGraphFromFile(“MainMenuLayer.ccbi”) to createSceneWithNodeGraphFromFile(“CocosBuilder/MainMenuLayer.ccbi”); and it finds the file but throws an alert and shows nothing but a black screen. Alert tells that “Get data from file(GUI_MainMenu.png) failed![](”. That’s the name of my atlas with buttons but it’s not PNG, it’s pvr.ccz. Anyway it can’t find it.

Honestly, I’m completely lost with this changes, I was already used to -hd, -ipad, -ipadhd suffixes. Can you please tell me how to structure all this and maybe tweak something in code to make it work? Should I write full file pathes in cocos2d-x now instead of relative paths that I was used to? Maybe I’ve missed something else?

Any help appreciated, thanks)


Seems like I’ve solved it!

Here’re simple rules you should follow when developing with cocos2d-x:

  1. Don’t use ~~hd,~~ipad, -ipadhd suffixes. Keep your files in separate folders such as Resources/hd, Resources/ipad and so on. If you had a font named font-hd.fnt and you’ve renamed simply by removing suffix – it won’t work, you should re-export it, the same goes for atlases and probably something else.
  2. Your Resources folder in Xcode should be “yellow” (group) but all it’s contents should be added in “blue” folders (references).
  3. When referencing any resource in code, you should add a path to it, i.e. write “Textures/Characters/player.png” instead of “player.png”. Textures folder lies in the folder from where you’re taking files for the current resolution (iphone/ for instance).
  4. Please uncheck “flatten paths” option in CocosBuilder’s Project Settings. This tiny recommendation could’ve saved me several hours.

And yes, initial setup for handling multiple resolutions is described perfectly here:

Hope this should help someone.