Asset Manager Overview

    During the development of the game, it is generally necessary to use a large number of images, audio and other resources to enrich the entire game, and a large number of resources can cause management difficulties. That’s why Creator provides the Asset Manager resource management module to help developers manage the use of their resources and greatly improve the development efficiency and experience.

    Asset Manager is a new resource manager from Creator in v2.4 that replaces the previous . The new Asset Manager resource management module has features for loading resources, finding resources, destroying resources, caching resources, Asset Bundle, and more. Compared with previous loader, Asset Manager has better performance, easier-to-use APIs, and greater extensibility. All functions and methods are accessible via assetManager and all types and enumerations are accessible via the AssetManager namespace.

    Note: we will maintain compatibility with loader for a period of time, but we strongly recommend using Asset Manager consistently for new projects.

    Refer to the following documentations for upgrading:

    In addition to applying resources to the corresponding components while editing scenes, Creator also supports dynamic loading and setting up of resources while the game is running. Asset Manager provides two ways to dynamically load resources:

    1. By placing resources in the resources directory, and working with APIs such as resources.load to achieve dynamic loading.
    2. developers can plan their own resource creation as Asset Bundle and load resources through the Asset Bundle’s load family of APIs. For example:

    The relevant APIs are listed below:

    All loaded resources are cached in assetManager.

    Preloading

    To reduce download latency, assetManager and Asset Bundle not only provides interfaces for loading resources, each interface also provides a corresponding preloaded version. Preloading in a game is an option that then allows finishing loading when it is really need it. Preloading will only download the necessary resources and will not perform deserialization or initialization. Therefore, it consumes less performance and is suitable for use during the game.

    1. resources.preload('images/background/spriteFrame', SpriteFrame);
    2. setTimeOut(this.loadAsset.bind(this), 10000);
    3. }
    4. loadAsset () {
    5. resources.load('images/background/spriteFrame', SpriteFrame, (err, asset) => {
    6. this.getComponent(Sprite).spriteFrame = asset;
    7. });
    8. }

    For more information on preloading, please refer to the documentation.

    Asset Bundle

    Partitioning scenes, resources, and code into multiple Asset Bundles and the loading of resources dynamically at runtime results in modularity of resources and allows loading corresponding resources when needed. For example:

    Please refer to the documentation for more information on Asset Bundle.

    Asset Manager provides a more convenient mechanism for releasing resources. When releasing a resource, you only need to focus on the resource itself and no longer on its dependent resources. The engine attempts to release its dependent resources based on the number of references, to reduce the complexity of managing resource releases for users. For example:

    1. resources.load('prefabs/enemy', Prefab, function (err, asset) {
    2. assetManager.releaseAsset(asset);

    Creator also provides a reference counting mechanism to help you control the reference and release of resources. For example:

    • When you no longer need to hold the resource, call decRef to reduce reference, decRef will also attempt an automatic release based on the reference count.

      1. this.texture.decRef();
      2. this.texture = null;

    Please refer to the documentation for more details.

    Cache Manager

    On some platforms, such as WeChat, it is possible to use the file system to cache some remote resources because a file system exists. In this case, a cache manager is required to manage all cache resources, such as caching resources, clearing cache resources, modifying cache cycles, etc. . Creator provides a cache manager on all platforms where file systems exist that allows adding, deleting, changing, and checking the cache. For example:

    Please refer to the documentation for more information on Cache Manager.

    Some of the interfaces for assetManager and Asset Bundle have an additional options parameter, which greatly increase the flexibility and extend the space. In addition to configuring the builtin parameters of Creator, it is also possible to customize any of the parameters in options, and these parameters will be provided to the downloader, parser, and loading pipeline.

    1. bundle.loadScene('test', {priority: 3}, callback);

    For more information on options parameter, please refer to the documentation.

    If it is not necessary to configure the engine’s builtin parameters or custom parameters to extend the engine’s functionality, ignore it and use the simpler API interfaces, such as resources.load.

    Loading Pipeline