Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Bundle

A bundle contains an amount of assets(includes scene), you can load, preload, release asset which is in this bundle

Hierarchy

  • Bundle

Index

Properties

Private _config

_config: Config = new Config()

Accessors

base

  • get base(): string

Private config

  • get config(): Config

deps

  • get deps(): string[]

name

  • get name(): string

Methods

destroy

  • _destroy(): void

get

  • get<T>(path: string, type?: AssetType<T> | null): T | null
  • Get cached asset within this bundle by path and type.
    After you load asset with {{#crossLink "Bundle/load:method"}}{{/crossLink}} or {{#crossLink "Bundle/loadDir:method"}}{{/crossLink}}, you can acquire them by passing the path to this API.

    NOTE:The path and type parameters passed need to be the same as those passed to Bundle.load, otherwise it may return some other resources with the same name!

    example

    bundle1.get('music/hit', cc.AudioClip);

    Type parameters

    Parameters

    • path: string

      The path of asset

    • Optional type: AssetType<T> | null

      Only asset of type will be returned if this argument is supplied.

    Returns T | null

    • the asset has been cached

getAssetInfo

  • getAssetInfo(uuid: string): IAssetInfo | null
  • Get asset's info with uuid

    method

    getAssetInfo

    example

    var info = bundle.getAssetInfo('fcmR3XADNLgJ1ByKhqcC5Z');

    Parameters

    • uuid: string

      The asset's uuid

    Returns IAssetInfo | null

    info

getDirWithPath

  • getDirWithPath(path: string, type?: AssetType | null, out?: IAddressableInfo[]): IAddressableInfo[]
  • Get all asset's info within specific folder

    example

    var infos = []; bundle.getDirWithPath('images', cc.Texture2D, infos);

    Parameters

    • path: string

      The relative path of folder, such as 'images'

    • Optional type: AssetType | null

      The constructor should be used to filter paths

    • Optional out: IAddressableInfo[]

      The output array

    Returns IAddressableInfo[]

    Infos

getInfoWithPath

  • getInfoWithPath(path: string, type?: AssetType | null): IAddressableInfo | null
  • Get asset's info using path, only valid when asset is in bundle folder.

    example

    var info = bundle.getInfoWithPath('image/a', cc.Texture2D);

    Parameters

    • path: string

      The relative path of asset, such as 'images/a'

    • Optional type: AssetType | null

      The constructor of asset, such as cc.Texture2D

    Returns IAddressableInfo | null

    The asset info

getSceneInfo

  • getSceneInfo(name: string): ISceneInfo | null
  • Get scene'info with name

    method

    getSceneInfo

    example

    var info = bundle.getSceneInfo('first.fire');

    Parameters

    • name: string

      The name of scene

    Returns ISceneInfo | null

    info

init

  • init(options: IConfigOption): void

load

  • load<T>(paths: string, type: AssetType<T> | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<T> | null): void
  • load<T>(paths: string[], type: AssetType<T> | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<T[]> | null): void
  • load<T>(paths: string, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<T> | null): void
  • load<T>(paths: string[], onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<T[]> | null): void
  • load<T>(paths: string, onComplete?: CompleteCallbackWithData<T> | null): void
  • load<T>(paths: string[], onComplete?: CompleteCallbackWithData<T[]> | null): void
  • load<T>(paths: string, type: AssetType<T> | null, onComplete?: CompleteCallbackWithData<T> | null): void
  • load<T>(paths: string[], type: AssetType<T> | null, onComplete?: CompleteCallbackWithData<T[]> | null): void
  • Load the asset within this bundle by the path which is relative to bundle's path

    example

    // load the texture (${project}/assets/resources/textures/background.jpg) from resources cc.resources.load('textures/background', cc.Texture2D, (err, texture) => console.log(err)); // load the audio (${project}/assets/resources/music/hit.mp3) from resources cc.resources.load('music/hit', cc.AudioClip, (err, audio) => console.log(err)); // load the prefab (${project}/assets/bundle1/misc/character/cocos) from bundle1 folder bundle1.load('misc/character/cocos', cc.Prefab, (err, prefab) => console.log(err)); // load the sprite frame (${project}/assets/some/xxx/bundle2/imgs/cocos.png) from bundle2 folder bundle2.load('imgs/cocos', cc.SpriteFrame, null, (err, spriteFrame) => console.log(err));

    Type parameters

    Parameters

    • paths: string

      Paths of the target assets.The path is relative to the bundle's folder, extensions must be omitted.

    • type: AssetType<T> | null

      Only asset of type will be loaded if this argument is supplied.

    • onProgress: ProgressCallback | null

      Callback invoked when progression change.

    • onComplete: CompleteCallbackWithData<T> | null

      Callback invoked when all assets loaded.

    Returns void

  • Type parameters

    Parameters

    • paths: string[]
    • type: AssetType<T> | null
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<T[]> | null

    Returns void

  • Type parameters

    Parameters

    • paths: string
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<T> | null

    Returns void

  • Type parameters

    Parameters

    • paths: string[]
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<T[]> | null

    Returns void

  • Type parameters

    Parameters

    • paths: string
    • Optional onComplete: CompleteCallbackWithData<T> | null

    Returns void

  • Type parameters

    Parameters

    • paths: string[]
    • Optional onComplete: CompleteCallbackWithData<T[]> | null

    Returns void

  • Type parameters

    Parameters

    • paths: string
    • type: AssetType<T> | null
    • Optional onComplete: CompleteCallbackWithData<T> | null

    Returns void

  • Type parameters

    Parameters

    • paths: string[]
    • type: AssetType<T> | null
    • Optional onComplete: CompleteCallbackWithData<T[]> | null

    Returns void

loadDir

  • loadDir<T>(dir: string, type: AssetType<T> | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<T[]> | null): void
  • loadDir<T>(dir: string, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<T[]> | null): void
  • loadDir<T>(dir: string, onComplete?: CompleteCallbackWithData<T[]> | null): void
  • loadDir<T>(dir: string, type: AssetType<T> | null, onComplete?: CompleteCallbackWithData<T[]> | null): void
  • Load all assets under a folder inside the bundle folder.

    Note: All asset paths in Creator use forward slashes, paths using backslashes will not work.

    example

    // load all audios (resources/audios/) cc.resources.loadDir('audios', cc.AudioClip, (err, audios) => {}); // load all textures in "resources/imgs/" cc.resources.loadDir('imgs', cc.Texture2D, null, function (err, textures) { var texture1 = textures[0]; var texture2 = textures[1]; }); // load all prefabs (${project}/assets/bundle1/misc/characters/) from bundle1 folder bundle1.loadDir('misc/characters', cc.Prefab, (err, prefabs) => console.log(err)); // load all sprite frame (${project}/assets/some/xxx/bundle2/skills/) from bundle2 folder bundle2.loadDir('skills', cc.SpriteFrame, null, (err, spriteFrames) => console.log(err));

    Type parameters

    Parameters

    • dir: string

      path of the target folder.The path is relative to the bundle folder, extensions must be omitted.

    • type: AssetType<T> | null

      Only asset of type will be loaded if this argument is supplied.

    • onProgress: ProgressCallback | null

      Callback invoked when progression change.

    • onComplete: CompleteCallbackWithData<T[]> | null

      A callback which is called when all assets have been loaded, or an error occurs.

    Returns void

  • Type parameters

    Parameters

    • dir: string
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<T[]> | null

    Returns void

  • Type parameters

    Parameters

    • dir: string
    • Optional onComplete: CompleteCallbackWithData<T[]> | null

    Returns void

  • Type parameters

    Parameters

    • dir: string
    • type: AssetType<T> | null
    • Optional onComplete: CompleteCallbackWithData<T[]> | null

    Returns void

loadScene

  • loadScene(sceneName: string, options: IAssetOptions | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<SceneAsset> | null): void
  • loadScene(sceneName: string, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<SceneAsset> | null): void
  • loadScene(sceneName: string, options: IAssetOptions | null, onComplete?: CompleteCallbackWithData<SceneAsset> | null): void
  • loadScene(sceneName: string, onComplete?: CompleteCallbackWithData<SceneAsset> | null): void
  • Loads the scene within this bundle by its name.

    example

    bundle1.loadScene('first', (err, sceneAsset) => cc.director.runScene(sceneAsset));

    Parameters

    • sceneName: string

      The name of the scene to load.

    • options: IAssetOptions | null

      Some optional parameters

    • onProgress: ProgressCallback | null

      Callback invoked when progression change.

    • onComplete: CompleteCallbackWithData<SceneAsset> | null

      callback, will be called after scene launched.

    Returns void

  • Parameters

    • sceneName: string
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<SceneAsset> | null

    Returns void

  • Parameters

    • sceneName: string
    • options: IAssetOptions | null
    • Optional onComplete: CompleteCallbackWithData<SceneAsset> | null

    Returns void

  • Parameters

    • sceneName: string
    • Optional onComplete: CompleteCallbackWithData<SceneAsset> | null

    Returns void

preload

  • preload(paths: string | string[], type: AssetType | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<RequestItem[]> | null): void
  • preload(paths: string | string[], onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<RequestItem[]> | null): void
  • preload(paths: string | string[], onComplete?: CompleteCallbackWithData<RequestItem[]> | null): void
  • preload(paths: string | string[], type: AssetType | null, onComplete?: CompleteCallbackWithData<RequestItem[]> | null): void
  • Preload the asset within this bundle by the path which is relative to bundle's path. After calling this method, you still need to finish loading by calling Bundle.load. It will be totally fine to call Bundle.load at any time even if the preloading is not yet finished

    example

    // preload the texture (${project}/assets/resources/textures/background.jpg) from resources cc.resources.preload('textures/background', cc.Texture2D); // preload the audio (${project}/assets/resources/music/hit.mp3) from resources cc.resources.preload('music/hit', cc.AudioClip); // wait for while cc.resources.load('music/hit', cc.AudioClip, (err, audioClip) => {});

    • // preload the prefab (${project}/assets/bundle1/misc/character/cocos) from bundle1 folder bundle1.preload('misc/character/cocos', cc.Prefab); // load the sprite frame of (${project}/assets/bundle2/imgs/cocos.png) from bundle2 folder bundle2.preload('imgs/cocos', cc.SpriteFrame); // wait for while bundle2.load('imgs/cocos', cc.SpriteFrame, (err, spriteFrame) => {});

    Parameters

    • paths: string | string[]

      Paths of the target asset.The path is relative to bundle folder, extensions must be omitted.

    • type: AssetType | null

      Only asset of type will be loaded if this argument is supplied.

    • onProgress: ProgressCallback | null

      Callback invoked when progression change.

    • onComplete: CompleteCallbackWithData<RequestItem[]> | null

      Callback invoked when the resource loaded.

    Returns void

  • Parameters

    • paths: string | string[]
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

  • Parameters

    • paths: string | string[]
    • Optional onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

  • Parameters

    • paths: string | string[]
    • type: AssetType | null
    • Optional onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

preloadDir

  • preloadDir(dir: string, type: AssetType | null, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<RequestItem[]> | null): void
  • preloadDir(dir: string, onProgress: ProgressCallback | null, onComplete: CompleteCallbackWithData<RequestItem[]> | null): void
  • preloadDir(dir: string, onComplete?: CompleteCallbackWithData<RequestItem[]> | null): void
  • preloadDir(dir: string, type: AssetType | null, onComplete?: CompleteCallbackWithData<RequestItem[]> | null): void
  • Preload all assets under a folder inside the bundle folder.
    After calling this method, you still need to finish loading by calling Bundle.loadDir. It will be totally fine to call Bundle.loadDir at any time even if the preloading is not yet finished

    example

    // preload all audios (resources/audios/) cc.resources.preloadDir('audios', cc.AudioClip); // preload all textures in "resources/imgs/" cc.resources.preloadDir('imgs', cc.Texture2D); // wait for while cc.resources.loadDir('imgs', cc.Texture2D, (err, textures) => {}); // preload all prefabs (${project}/assets/bundle1/misc/characters/) from bundle1 folder bundle1.preloadDir('misc/characters', cc.Prefab); // preload all sprite frame (${project}/assets/some/xxx/bundle2/skills/) from bundle2 folder bundle2.preloadDir('skills', cc.SpriteFrame); // wait for while bundle2.loadDir('skills', cc.SpriteFrame, (err, spriteFrames) => {});

    Parameters

    • dir: string

      path of the target folder.The path is relative to the bundle folder, extensions must be omitted.

    • type: AssetType | null

      Only asset of type will be preloaded if this argument is supplied.

    • onProgress: ProgressCallback | null

      Callback invoked when progression change.

    • onComplete: CompleteCallbackWithData<RequestItem[]> | null

      A callback which is called when all assets have been loaded, or an error occurs.

    Returns void

  • Parameters

    • dir: string
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

  • Parameters

    • dir: string
    • Optional onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

  • Parameters

    • dir: string
    • type: AssetType | null
    • Optional onComplete: CompleteCallbackWithData<RequestItem[]> | null

    Returns void

preloadScene

  • preloadScene(sceneName: string, options: IAssetOptions | null, onProgress: ProgressCallback, onComplete: CompleteCallbackNoData | null): void
  • preloadScene(sceneName: string, onProgress: ProgressCallback | null, onComplete: CompleteCallbackNoData | null): void
  • preloadScene(sceneName: string, options: IAssetOptions | null, onComplete?: CompleteCallbackNoData | null): void
  • preloadScene(sceneName: string, onComplete?: CompleteCallbackNoData | null): void
  • Preloads the scene within this bundle by its name. After calling this method, you still need to finish loading by calling Bundle.loadScene or cc.director.loadScene.It will be totally fine to call Bundle.loadDir at any time even if the preloading is not yet finished

    example

    bundle1.preloadScene('first'); // wait for a while bundle1.loadScene('first', (err, scene) => cc.director.runScene(scene));

    Parameters

    • sceneName: string

      The name of the scene to preload.

    • options: IAssetOptions | null

      Some optional parameters

    • onProgress: ProgressCallback

      callback, will be called when the load progression change.

    • onComplete: CompleteCallbackNoData | null

      callback, will be called after scene loaded.

    Returns void

  • Parameters

    • sceneName: string
    • onProgress: ProgressCallback | null
    • onComplete: CompleteCallbackNoData | null

    Returns void

  • Parameters

    • sceneName: string
    • options: IAssetOptions | null
    • Optional onComplete: CompleteCallbackNoData | null

    Returns void

  • Parameters

    • sceneName: string
    • Optional onComplete: CompleteCallbackNoData | null

    Returns void

release

  • release(path: string, type?: AssetType | null): void
  • Release the asset loaded by {{#crossLink "Bundle/load:method"}}{{/crossLink}} or {{#crossLink "Bundle/loadDir:method"}}{{/crossLink}} and it's dependencies. Refer to {{#crossLink "AssetManager/releaseAsset:method"}}{{/crossLink}} for detailed informations.

    NOTE:The path and type parameters passed need to be the same as those passed to Bundle.load, otherwise it may release some other resources with the same name!

    example

    // release a texture which is no longer need bundle1.release('misc/character/cocos');

    Parameters

    • path: string

      The path of asset

    • Optional type: AssetType | null

      Only asset of type will be released if this argument is supplied.

    Returns void

releaseAll

  • releaseAll(): void
  • Release all assets within this bundle. Refer to {{#crossLink "AssetManager/releaseAll:method"}}{{/crossLink}} for detailed informations.

    example

    // release all asset within bundle1 bundle1.releaseAll();

    Returns void

Private releaseUnusedAssets

  • releaseUnusedAssets(): void
  • Release all unused assets within this bundle. Refer to {{#crossLink "AssetManager/releaseAll:method"}}{{/crossLink}} for detailed informations.

    example

    // release all unused asset within bundle1 bundle1.releaseUnusedAssets();

    Returns void

Generated using TypeDoc