• LoadingItems 类型
    • 索引
      • 属性(properties)
      • 方法
  • Details
    • 属性(properties)
      • map
      • completed
      • totalCount
      • completedCount
      • active
        • 参数列表
      • 示例
      • onComplete
        • 参数列表
      • 示例
      • create
        • 参数列表
      • 示例
      • getQueue
        • 参数列表
      • itemComplete
        • 参数列表
      • append
        • 参数列表
      • allComplete
      • isCompleted
      • isItemCompleted
        • 参数列表
      • exists
        • 参数列表
      • getContent
        • 参数列表
      • getError
        • 参数列表
      • addListener
        • 参数列表
      • hasListener
        • 参数列表
      • remove
        • 参数列表
      • removeAllListeners
        • 参数列表
      • itemComplete
        • 参数列表
      • destroy
      • invoke
        • 参数列表
      • add
        • 参数列表
      • hasEventListener
        • 参数列表
      • removeAll
        • 参数列表

    LoadingItems 类型

    继承于 CallbacksInvoker

    模块: cc父模块: cc

    LoadingItems 是一个加载对象队列,可以用来输送加载对象到加载管线中。请不要直接使用 new 构造这个类的对象,你可以使用 LoadingItems.create 来创建一个新的加载队列,这样可以允许我们的内部对象池回收并重利用加载队列。它有一个 map 属性用来存放加载项,在 map 对象中已 url 为 key 值。每个对象都会包含下列属性:

    • id:该对象的标识,通常与 url 相同。
    • url:路径
    • type: 类型,它这是默认的 URL 的扩展名,可以手动指定赋值。
    • error:pipeline 中发生的错误将被保存在这个属性中。
    • content: pipeline 中处理的临时结果,最终的结果也将被存储在这个属性中。
    • complete:该标志表明该对象是否通过 pipeline 完成。
    • states:该对象存储每个管道中对象经历的状态,状态可以是 Pipeline.ItemState.WORKING | Pipeline.ItemState.ERROR | Pipeline.ItemState.COMPLETE对象可容纳其他自定义属性。每个 LoadingItems 对象都会在 onComplete 回调之后被销毁,所以请不要持有它的引用并在结束回调之后依赖它的内容执行任何逻辑,有这种需求的话你可以提前复制它的内容。

    索引

    属性(properties)
    • map Object 存储所有加载项的对象。
    • completed Object 存储已经完成的加载项。
    • totalCount Number 所有加载项的总数。
    • completedCount Number 所有完成加载项的总数。
    • active Boolean 是否启用。
    方法
    • onProgress 这个回调函数将在 item 加载结束后被调用。
    • onComplete 该函数将在加载队列全部完成时被调用。
    • create LoadingItems 的构造函数,这种构造方式会重用内部对象缓冲池中的 LoadingItems 队列,以尽量避免对象创建。
    • getQueue 通过 item 对象获取它的 LoadingItems 队列。
    • itemComplete 通知 LoadingItems 队列一个 item 对象已完成,请不要调用这个函数,除非你知道自己在做什么。
    • append 向一个 LoadingItems 队列添加加载项。
    • allComplete 完成一个 LoadingItems 队列,请不要调用这个函数,除非你知道自己在做什么。
    • isCompleted 检查是否所有加载项都已经完成。
    • isItemCompleted 通过 id 检查指定加载项是否已经加载完成。
    • exists 通过 id 检查加载项是否存在。
    • getContent 通过 id 获取指定对象的内容。
    • getError 通过 id 获取指定对象的错误信息。
    • addListener 监听加载项(通过 key 指定)的完成事件。
    • hasListener 检查指定的加载项是否有完成事件监听器。
    • remove 移除指定加载项已经注册的完成事件监听器。
    • removeAllListeners 删除指定目标的所有完成事件监听器。
    • itemComplete 通知 LoadingItems 队列一个 item 对象已完成,请不要调用这个函数,除非你知道自己在做什么。
    • destroy 销毁一个 LoadingItems 队列,这个队列对象会被内部缓冲池回收,所以销毁后的所有内部信息都是不可依赖的。
    • invoke
    • add
    • hasEventListener Check if the specified key has any registered callback. If a callback is also specified,…
    • removeAll Removes all callbacks registered in a certain event type or all callbacks registered with a certain target

    Details

    属性(properties)

    map
    存储所有加载项的对象。
    metadescription
    类型Object
    定义于cocos2d/core/load-pipeline/loading-items.js:212
    completed
    存储已经完成的加载项。
    metadescription
    类型Object
    定义于cocos2d/core/load-pipeline/loading-items.js:220
    totalCount
    所有加载项的总数。
    metadescription
    类型Number
    定义于cocos2d/core/load-pipeline/loading-items.js:228
    completedCount
    所有完成加载项的总数。
    metadescription
    类型Number
    定义于cocos2d/core/load-pipeline/loading-items.js:236
    active
    是否启用。
    metadescription
    类型Boolean
    定义于cocos2d/core/load-pipeline/loading-items.js:244



    #### 方法



    ##### onProgress


    这个回调函数将在 item 加载结束后被调用。你可以在构造时传递这个回调函数或者是在构造之后直接设置。

    metadescription
    定义于cocos2d/core/load-pipeline/loading-items.js:179
    参数列表
    • completedCount Number The number of the items that are already completed.
    • totalCount Number The total number of the items.
    • item Object The latest item which flow out the pipeline.
    示例
    1. loadingItems.onProgress = function (completedCount, totalCount, item) {
    2. var progress = (100 * completedCount / totalCount).toFixed(2);
    3. cc.log(progress + '%');
    4. }
    onComplete

    该函数将在加载队列全部完成时被调用。你可以在构造时传递这个回调函数或者是在构造之后直接设置。

    metadescription
    定义于cocos2d/core/load-pipeline/loading-items.js:195
    参数列表
    • errors Array All errored urls will be stored in this array, if no error happened, then it will be null
    • items LoadingItems All items.
    示例
    1. loadingItems.onComplete = function (errors, items) {
    2. if (error)
    3. cc.log('Completed with ' + errors.length + ' errors');
    4. else
    5. cc.log('Completed ' + items.totalCount + ' items');
    6. }
    create

    LoadingItems 的构造函数,这种构造方式会重用内部对象缓冲池中的 LoadingItems 队列,以尽量避免对象创建。你可以传递 onProgress 和 onComplete 回调函数来获知加载进度信息。

    metadescription
    返回LoadingItems
    定义于cocos2d/core/load-pipeline/loading-items.js:292
    参数列表
    • pipeline Pipeline The pipeline to process the queue.
    • urlList Array The items array.
    • onProgress Function The progression callback, refer to LoadingItems.onProgress
    • onComplete Function The completion callback, refer to LoadingItems.onComplete
    示例
    1. cc.LoadingItems.create(cc.loader, ['a.png', 'b.plist'], function (completedCount, totalCount, item) {
    2. var progress = (100 * completedCount / totalCount).toFixed(2);
    3. cc.log(progress + '%');
    4. }, function (errors, items) {
    5. if (errors) {
    6. for (var i = 0; i < errors.length; ++i) {
    7. cc.log('Error url: ' + errors[i] + ', error: ' + items.getError(errors[i]));
    8. }
    9. }
    10. else {
    11. var result_a = items.getContent('a.png');
    12. // ...
    13. }
    14. })
    getQueue

    通过 item 对象获取它的 LoadingItems 队列。

    metadescription
    返回LoadingItems
    定义于cocos2d/core/load-pipeline/loading-items.js:359
    参数列表
    • item Object The item to query
    itemComplete

    通知 LoadingItems 队列一个 item 对象已完成,请不要调用这个函数,除非你知道自己在做什么。

    metadescription
    定义于cocos2d/core/load-pipeline/loading-items.js:371
    参数列表
    • item Object The item which has completed
    append

    向一个 LoadingItems 队列添加加载项。

    metadescription
    返回Array
    定义于cocos2d/core/load-pipeline/loading-items.js:439
    参数列表
    • urlList Array The url list to be appended, the url can be object or string
    allComplete

    完成一个 LoadingItems 队列,请不要调用这个函数,除非你知道自己在做什么。

    metadescription
    定义于cocos2d/core/load-pipeline/loading-items.js:523
    isCompleted

    检查是否所有加载项都已经完成。

    metadescription
    返回Boolean
    定义于cocos2d/core/load-pipeline/loading-items.js:535
    isItemCompleted

    通过 id 检查指定加载项是否已经加载完成。

    metadescription
    返回Boolean
    定义于cocos2d/core/load-pipeline/loading-items.js:545
    参数列表
    • id String The item's id.
    exists

    通过 id 检查加载项是否存在。

    metadescription
    返回Boolean
    定义于cocos2d/core/load-pipeline/loading-items.js:556
    参数列表
    • id String The item's id.
    getContent

    通过 id 获取指定对象的内容。

    metadescription
    返回Object
    定义于cocos2d/core/load-pipeline/loading-items.js:567
    参数列表
    • id String The item's id.
    getError

    通过 id 获取指定对象的错误信息。

    metadescription
    返回Object
    定义于cocos2d/core/load-pipeline/loading-items.js:589
    参数列表
    • id String The item's id.
    addListener

    监听加载项(通过 key 指定)的完成事件。

    metadescription
    返回Boolean
    定义于cocos2d/core/load-pipeline/loading-items.js:610
    参数列表
    • key String
    • callback Function can be null
    • target Object can be null
    hasListener

    检查指定的加载项是否有完成事件监听器。如果同时还指定了一个回调方法,并且回调有注册,它只会返回 true。

    metadescription
    返回Boolean
    定义于cocos2d/core/load-pipeline/loading-items.js:621
    参数列表
    • key String
    • callback Function
    • target Object
    remove

    移除指定加载项已经注册的完成事件监听器。只会删除 key, callback, target 均匹配的监听器。

    metadescription
    返回Boolean
    定义于cocos2d/core/load-pipeline/loading-items.js:636
    参数列表
    • key String
    • callback Function
    • target Object
    removeAllListeners

    删除指定目标的所有完成事件监听器。

    metadescription
    定义于cocos2d/core/load-pipeline/loading-items.js:651
    参数列表
    • key String | Object The event key to be removed or the target to be removed
    itemComplete

    通知 LoadingItems 队列一个 item 对象已完成,请不要调用这个函数,除非你知道自己在做什么。

    metadescription
    定义于cocos2d/core/load-pipeline/loading-items.js:683
    参数列表
    • id String The item url
    destroy

    销毁一个 LoadingItems 队列,这个队列对象会被内部缓冲池回收,所以销毁后的所有内部信息都是不可依赖的。

    metadescription
    定义于cocos2d/core/load-pipeline/loading-items.js:723
    invoke
    metadescription
    定义于cocos2d/core/platform/callbacks-invoker.js:236
    参数列表
    • key String
    • p1 Any
    • p2 Any
    • p3 Any
    • p4 Any
    • p5 Any
    add
    metadescription
    定义于cocos2d/core/platform/callbacks-invoker.js:97
    参数列表
    • key String
    • callback Function
    • target Object can be null
    hasEventListener

    Check if the specified key has any registered callback. If a callback is also specified,it will only return true if the callback is registered.

    metadescription
    返回Boolean
    定义于cocos2d/core/platform/callbacks-invoker.js:112
    参数列表
    • key String
    • callback Function
    • target Object
    removeAll

    Removes all callbacks registered in a certain event type or all callbacks registered with a certain target

    metadescription
    定义于cocos2d/core/platform/callbacks-invoker.js:154
    参数列表
    • keyOrTarget String | Object The event key to be removed or the target to be removed