Outdated Docs > Mechanism of loading resources

Mechanism of Loading Resources

Centralized strategy

This strategy put all retina resources into a separate directory.

This strategy is not suitable for multi-resolution adaption, because there are too many resolutions on Android. You can not provide all resources for all resolutions, then set searching order based on resolutions, such as

std::vector resDirOrders;
if (resolution is reslution1)
else if (resolution is resolution2)


What is the new mechanism

The mechanism is:
Try to find a picture in the paths set by FileUtils::setSearchPaths() firstly, if it’s not found, then find the picture in Resources/

// set searching paths to "/mnt/sd/example" and "/data/data/org.cocos2dx.example"
vector 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)
Sprite *pSprite = Sprite::create("1.png");  

It is easy to add searching path to engine. Using this method, you can load resources into a path you know, then set this path to engine. Engine will find a resource in this path if needed.

Developer guide

If you want to share some resources between different resolutions, then you can put all shared resources in Resources/, and put resolution specified resources in different directories.
You can refer to samples/HelloCpp for more information.

For example:

    * resources/
    *** ipad/
    ***** background.png
    *** iphone4/
    *** background.png
    ** sharedResource.png
    * classes/

distributed-resource-directory.png (124.8 kB) zhangxm, 2013-01-28 10:22

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.