Loading and Preloading
Author: Santy-Wang, Xunyi
In order to minimize download times, most of the loading interfaces in Asset Manager, including load
, loadDir
, and loadScene
have their own corresponding preloaded versions. The parameters used for the loading interfaces and the preloading interfaces are exactly the same, with the following differences:
- Preloading will only download the resources and will not parse or initialize them.
- Preloading will be more limited during the loading process, e.g. the maximum number of download concurrently will be smaller.
- Preloading has a lower priority, and when multiple resources are waiting to be downloaded, the preloaded resources will be downloaded last.
- Since the preload does not do any parsing, no available resources are returned when all the preloads load are complete.
Compared to previous versions of Creator v2.4, these optimizations reduce the preloading performance loss and ensure a smooth gaming experience. You can make full use of the network bandwidth during the game to reduce the loading time of subsequent resources.
Since the preload does not parse the resources, you need to parse and initialize the resources with the loading interface to complete the resource loading after the preload is complete. For example:
cc.resources.preload('images/background', cc.SpriteFrame);
// Wait for while
cc.resources.load('images/background', cc.SpriteFrame, function (err, spriteFrame) {
spriteFrame.addRef();
self.getComponent(cc.Sprite).spriteFrame = spriteFrame;
});
Note: Loading does not need to wait until the preload is complete, you can load at any time. The normal loading interface will directly reuse the content that was already downloaded during the preload process, reducing the load time