Selecting resource files
Your game has images of each resolution for multiresolution adaption. If you have resolved to find an image for each resolution, your application logic is very complicated. Cocos2d-x has a search path mechanism for solving this problem. In this recipe, we will explain this search path mechanism.
Getting ready
If you want to share some resources between different resolutions, then you can put all the shared resources in the Resources
folder, and put the resolution-specified resources in different folders as shown in the following image.
CloseNormal.png
and CloseSelected.png
are shared resources between different resolutions. However, HelloWorld.png
is a resolution-specified resource.
How to do it...
You can set the priority to search resources for Cocos2d-x as follows:
std::vector<std::string> searchPaths; searchPaths.push_back("ipad"); FileUtils::setSearchPaths(searchPaths); Sprite *sprite = Sprite::create("HelloWorld.png"); Sprite *close = Sprite::create("CloseNormal...