From 42fe5c3eacd0a423bc9af662daee80a2aab39202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=AE=B6=E8=BE=89?= <35832931+ColinCollins@users.noreply.github.com> Date: Wed, 27 Jun 2018 09:52:17 +0800 Subject: [PATCH] add progress param to the preloadScene (#2907) --- cocos2d/core/CCDirector.js | 19 +++++++++++++++++-- cocos2d/core/load-pipeline/CCLoader.js | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 3563e17a46..851f4d21b2 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -582,14 +582,29 @@ cc.Director.prototype = { * * @method preloadScene * @param {String} sceneName - The name of the scene to preload. + * @param {Function} [onProgress] - callback, will be called when the load progression change. + * @param {Number} onProgress.completedCount - The number of the items that are already completed + * @param {Number} onProgress.totalCount - The total number of the items + * @param {Object} onProgress.item - The latest item which flow out the pipeline * @param {Function} [onLoaded] - callback, will be called after scene loaded. * @param {Error} onLoaded.error - null or the error object. */ - preloadScene: function (sceneName, onLoaded) { + preloadScene: function (sceneName, onProgress, onLoaded) { + if (onLoaded === undefined) { + onLoaded = onProgress; + onProgress = null; + } + var info = this._getSceneUuid(sceneName); if (info) { this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName); - cc.loader.load({ uuid: info.uuid, type: 'uuid' }, function (error, asset) { + cc.loader.load({ uuid: info.uuid, type: 'uuid' }, + function (completedCount, totalCount, item) { + if (onProgress) { + onProgress(completedCount, totalCount, item); + } + }, + function (error, asset) { if (error) { cc.errorID(1210, sceneName, error.message); } diff --git a/cocos2d/core/load-pipeline/CCLoader.js b/cocos2d/core/load-pipeline/CCLoader.js index c4520929c5..8a1d986b66 100644 --- a/cocos2d/core/load-pipeline/CCLoader.js +++ b/cocos2d/core/load-pipeline/CCLoader.js @@ -112,7 +112,7 @@ function CCLoader () { this.downloader = downloader; /** - * The downloader in cc.loader's pipeline, it's by default the third pipe. + * The loader in cc.loader's pipeline, it's by default the third pipe. * It's used to parse downloaded content with several handlers: JSON, image, plist, fnt, uuid. * You can add your own download function with addLoadHandlers * @property loader