AssetManager Class

Module: cc

This module controls asset's behaviors and information, include loading, releasing etc. it is a singleton All member can be accessed with cc.assetManager.

Index

Properties
  • pipeline Pipeline Normal loading pipeline
  • fetchPipeline Pipeline Fetching pipeline
  • transformPipeline Pipeline Url transformer
  • bundles Cache The collection of bundle which is already loaded, you can remove cache with removeBundle
  • assets Cache The collection of asset which is already loaded, you can remove cache with releaseAsset
  • dependUtil DependUtil Manage relationship between asset and its dependencies
  • cacheAsset Boolean Whether or not cache the loaded asset
  • force Boolean Whether or not load asset forcely, if it is true, asset will be loaded regardless of error
  • utils Helper Some useful function
  • downloader Downloader Manage all downloading task
  • parser Parser Manage all parsing task
  • builtins Builtins Manage internal asset
  • packManager PackManager Manage all packed asset
  • cacheManager cc.AssetManager.CacheManager Cache manager is a module which controls all caches downloaded from server in non-web platform.
  • presets Object The preset of options
  • main Bundle The builtin 'main' bundle
  • resources Bundle The builtin 'resources' bundle
  • internal Bundle The builtin 'internal' bundle
Methods
  • init Initialize assetManager with options
  • getBundle Get the bundle which has been loaded
  • removeBundle Remove this bundle.
  • loadAny General interface used to load assets with a progression callback and a complete callback.
  • preloadAny General interface used to preload assets with a progression callback and a complete callback.It is highly recommended that you use more simple API, such as preloadRes, preloadResDir etc.
  • postLoadNative Load native file of asset, if you check the option 'Async Load Assets', you may need to load native file with this before you use the asset
  • loadRemote Load remote asset with url, such as audio, image, text and so on.
  • loadScript Load script
  • loadBundle load bundle
  • releaseAsset Release asset and it's dependencies.
  • releaseUnusedAssets Release all unused assets.
  • releaseAll Release all assets.

Details

Properties

pipeline

Normal loading pipeline

meta description
Type Pipeline
Defined in cocos2d/core/asset-manager/CCAssetManager.js:71
fetchPipeline

Fetching pipeline

meta description
Type Pipeline
Defined in cocos2d/core/asset-manager/CCAssetManager.js:83
transformPipeline

Url transformer

meta description
Type Pipeline
Defined in cocos2d/core/asset-manager/CCAssetManager.js:95
bundles

The collection of bundle which is already loaded, you can remove cache with removeBundle

meta description
Type Cache
Defined in cocos2d/core/asset-manager/CCAssetManager.js:108
assets

The collection of asset which is already loaded, you can remove cache with releaseAsset

meta description
Type Cache
Defined in cocos2d/core/asset-manager/CCAssetManager.js:122
dependUtil

Manage relationship between asset and its dependencies

meta description
Type DependUtil
Defined in cocos2d/core/asset-manager/CCAssetManager.js:144
cacheAsset

Whether or not cache the loaded asset

meta description
Type Boolean
Defined in cocos2d/core/asset-manager/CCAssetManager.js:158
force

Whether or not load asset forcely, if it is true, asset will be loaded regardless of error

meta description
Type Boolean
Defined in cocos2d/core/asset-manager/CCAssetManager.js:170
utils

Some useful function

meta description
Type Helper
Defined in cocos2d/core/asset-manager/CCAssetManager.js:182
downloader

Manage all downloading task

meta description
Type Downloader
Defined in cocos2d/core/asset-manager/CCAssetManager.js:194
parser

Manage all parsing task

meta description
Type Parser
Defined in cocos2d/core/asset-manager/CCAssetManager.js:206
builtins

Manage internal asset

meta description
Type Builtins
Defined in cocos2d/core/asset-manager/CCAssetManager.js:218
packManager

Manage all packed asset

meta description
Type PackManager
Defined in cocos2d/core/asset-manager/CCAssetManager.js:230
cacheManager

Cache manager is a module which controls all caches downloaded from server in non-web platform.

meta description
Type cc.AssetManager.CacheManager
Defined in cocos2d/core/asset-manager/CCAssetManager.js:244
presets

The preset of options

meta description
Type Object
Defined in cocos2d/core/asset-manager/CCAssetManager.js:258
main

The builtin 'main' bundle

meta description
Type Bundle
Defined in cocos2d/core/asset-manager/CCAssetManager.js:317
resources

The builtin 'resources' bundle

meta description
Type Bundle
Defined in cocos2d/core/asset-manager/CCAssetManager.js:332
internal

The builtin 'internal' bundle

meta description
Type Bundle
Defined in cocos2d/core/asset-manager/CCAssetManager.js:347

Methods

init

Initialize assetManager with options

meta description
Defined in cocos2d/core/asset-manager/CCAssetManager.js:362
Parameters
getBundle

Get the bundle which has been loaded

meta description
Returns Bundle
Defined in cocos2d/core/asset-manager/CCAssetManager.js:390
Parameters
  • name String The name of bundle
Examples
// ${project}/assets/test1
cc.assetManager.getBundle('test1');

cc.assetManager.getBundle('resources');
removeBundle

Remove this bundle. NOTE: The asset whthin this bundle will not be released automatically, you can call releaseAll manually before remove it if you need

meta description
Defined in cocos2d/core/asset-manager/CCAssetManager.js:414
Parameters
  • bundle Bundle The bundle to be removed
loadAny

General interface used to load assets with a progression callback and a complete callback. You can achieve almost all effect you want with combination of requests and options. It is highly recommended that you use more simple API, such as load, loadDir etc. Every custom parameter in options will be distribute to each of requests. if request already has same one, the parameter in request will be given priority. Besides, if request has dependencies, options will distribute to dependencies too. Every custom parameter in requests will be tranfered to handler of downloader and parser as options. You can register you own handler downloader or parser to collect these custom parameters for some effect.

Reserved Keyword: uuid, url, path, dir, scene, type, priority, preset, audioLoadMode, ext, bundle, onFileProgress, maxConcurrency, maxRequestsPerFrame maxRetryCount, version, responseType, withCredentials, mimeType, timeout, header, reload, cacheAsset, cacheEnabled, Please DO NOT use these words as custom options!

meta description
Defined in cocos2d/core/asset-manager/CCAssetManager.js:432
Parameters
  • requests string | string[] | Object | Object[] The request you want to load
  • options Object Optional parameters
  • onProgress Function Callback invoked when progression change
    • finished Number The number of the items that are already completed
    • total Number The total number of the items
    • item RequestItem The current request item
  • onComplete Function Callback invoked when finish loading
    • err Error The error occured in loading process.
    • data Object The loaded content
Examples
cc.assetManager.loadAny({url: 'http://example.com/a.png'}, (err, img) => cc.log(img));
cc.assetManager.loadAny(['60sVXiTH1D/6Aft4MRt9VC'], (err, assets) => cc.log(assets));
cc.assetManager.loadAny([{ uuid: '0cbZa5Y71CTZAccaIFluuZ'}, {url: 'http://example.com/a.png'}], (err, assets) => cc.log(assets));
cc.assetManager.downloader.register('.asset', (url, options, onComplete) => {
     url += '?userName=' + options.userName + "&password=" + options.password;
     cc.assetManager.downloader.downloadFile(url, null, onComplete);
});
cc.assetManager.parser.register('.asset', (file, options, onComplete) => {
     var json = JSON.parse(file);
     var skin = json[options.skin];
     var model = json[options.model];
     onComplete(null, {skin, model});
});
cc.assetManager.loadAny({ url: 'http://example.com/my.asset', skin: 'xxx', model: 'xxx', userName: 'xxx', password: 'xxx' });
preloadAny

General interface used to preload assets with a progression callback and a complete callback.It is highly recommended that you use more simple API, such as preloadRes, preloadResDir etc. Everything about preload is just likes cc.assetManager.loadAny, the difference is cc.assetManager.preloadAny will only download asset but not parse asset. You need to invoke cc.assetManager.loadAny(preloadTask) to finish loading asset

meta description
Defined in cocos2d/core/asset-manager/CCAssetManager.js:498
Parameters
  • requests string | string[] | Object | Object[] The request you want to preload
  • options Object Optional parameters
  • onProgress Function Callback invoked when progression change
    • finished Number The number of the items that are already completed
    • total Number The total number of the items
    • item RequestItem The current request item
  • onComplete Function Callback invoked when finish preloading
    • err Error The error occured in preloading process.
    • items RequestItem[] The preloaded content
Examples
cc.assetManager.preloadAny('0cbZa5Y71CTZAccaIFluuZ', (err) => cc.assetManager.loadAny('0cbZa5Y71CTZAccaIFluuZ'));
postLoadNative

Load native file of asset, if you check the option 'Async Load Assets', you may need to load native file with this before you use the asset

meta description
Defined in cocos2d/core/asset-manager/CCAssetManager.js:539
Parameters
  • asset Asset The asset
  • options Object Some optional parameters
  • onComplete Function Callback invoked when finish loading
    • err Error The error occured in loading process.
Examples
cc.assetManager.postLoadNative(texture, (err) => console.log(err));
loadRemote

Load remote asset with url, such as audio, image, text and so on.

meta description
Defined in cocos2d/core/asset-manager/CCAssetManager.js:594
Parameters
  • url string The url of asset
  • options Object Some optional parameters
    • audioLoadMode cc.AudioClip.LoadMode Indicate which mode audio you want to load
    • ext string If the url does not have a extension name, you can specify one manually.
  • onComplete Function Callback invoked when finish loading
    • err Error The error occured in loading process.
    • asset Asset The loaded texture
Examples
cc.assetManager.loadRemote('http://www.cloud.com/test1.jpg', (err, texture) => console.log(err));
cc.assetManager.loadRemote('http://www.cloud.com/test2.mp3', (err, audioClip) => console.log(err));
cc.assetManager.loadRemote('http://www.cloud.com/test3', { ext: '.png' }, (err, texture) => console.log(err));
loadScript

Load script

meta description
Defined in cocos2d/core/asset-manager/CCAssetManager.js:643
Parameters
  • url string | string[] Url of the script
  • options Object Some optional paramters
    • async boolean Indicate whether or not loading process should be async
  • onComplete Function Callback when script loaded or failed
    • err Error The occurred error, null indicetes success
Examples
loadScript('http://localhost:8080/index.js', null, (err) => console.log(err));
loadBundle

load bundle

meta description
Defined in cocos2d/core/asset-manager/CCAssetManager.js:673
Parameters
  • nameOrUrl string The name or root path of bundle
  • options Object Some optional paramter, same like downloader.downloadFile
    • version string The version of this bundle, you can check config.json in this bundle
  • onComplete Function Callback when bundle loaded or failed
    • err Error The occurred error, null indicetes success
    • bundle Bundle The loaded bundle
Examples
loadBundle('http://localhost:8080/test', null, (err, bundle) => console.log(err));
releaseAsset

Release asset and it's dependencies. This method will not only remove the cache of the asset in assetManager, but also clean up its content. For example, if you release a texture, the texture asset and its gl texture data will be freed up. Notice, this method may cause the texture to be unusable, if there are still other nodes use the same texture, they may turn to black and report gl errors.

meta description
Defined in cocos2d/core/asset-manager/CCAssetManager.js:711
Parameters
  • asset Asset The asset to be released
Examples
// release a texture which is no longer need
cc.assetManager.releaseAsset(texture);
releaseUnusedAssets

Release all unused assets. Refer to releaseAsset for detailed informations.

meta description
Defined in cocos2d/core/asset-manager/CCAssetManager.js:737
releaseAll

Release all assets. Refer to releaseAsset for detailed informations.

meta description
Defined in cocos2d/core/asset-manager/CCAssetManager.js:756

results matching ""

    No results matching ""