From 57d8f90bad252be516e0058ba9f8854a62033cae Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Tue, 29 Nov 2016 14:08:14 +0800 Subject: [PATCH 01/12] fix mixins release --- cocos2d/core/platform/CCClass.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index afb2ce970c..6538ef47ca 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -41,7 +41,7 @@ var TYPO_TO_CORRECT = CC_DEV && { constructor: 'ctor' }; -var INVALID_STATICS = CC_DEV && ['name', '__ctors__', '__props__', 'arguments', 'call', 'apply', 'caller', +var INVALID_STATICS_DEV = CC_DEV && ['name', '__ctors__', '__props__', 'arguments', 'call', 'apply', 'caller', 'length', 'prototype']; var deferredInitializer = { @@ -404,7 +404,7 @@ function doDefine (className, baseClass, mixins, constructor, options) { // mixin statics (this will also copy editor attributes for component) for (var p in mixin) - if (mixin.hasOwnProperty(p) && INVALID_STATICS.indexOf(p) < 0) + if (mixin.hasOwnProperty(p) && (!CC_DEV || INVALID_STATICS_DEV.indexOf(p) < 0)) fireClass[p] = mixin[p]; // mixin attributes @@ -818,7 +818,7 @@ function CCClass (options) { var staticPropName; if (CC_DEV) { for (staticPropName in statics) { - if (INVALID_STATICS.indexOf(staticPropName) !== -1) { + if (INVALID_STATICS_DEV.indexOf(staticPropName) !== -1) { cc.error('Cannot define %s.%s because static member name can not be "%s".', name, staticPropName, staticPropName); } From 2e3355ab4f28c9e765fd27517351301711d846a9 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 30 Nov 2016 12:02:42 +0800 Subject: [PATCH 02/12] Fixing CCSGParticleSystem to read rotationIsDir is not a string error --- cocos2d/particle/CCSGParticleSystem.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cocos2d/particle/CCSGParticleSystem.js b/cocos2d/particle/CCSGParticleSystem.js index 4d33a4993e..68d30b2bf1 100644 --- a/cocos2d/particle/CCSGParticleSystem.js +++ b/cocos2d/particle/CCSGParticleSystem.js @@ -1339,8 +1339,10 @@ _ccsg.ParticleSystem = _ccsg.Node.extend({ locModeA.tangentialAccelVar = (pszTmp) ? parseFloat(pszTmp) : 0; // rotation is dir - var locRotationIsDir = locValueForKey("rotationIsDir", dictionary).toLowerCase(); - locModeA.rotationIsDir = (locRotationIsDir != null && (locRotationIsDir === "true" || locRotationIsDir === "1")); + var locRotationIsDir = locValueForKey("rotationIsDir", dictionary); + locRotationIsDir = ("" + locRotationIsDir).toLowerCase(); + locModeA.rotationIsDir = (locRotationIsDir === "true" || locRotationIsDir === "1"); + } else if (this.emitterMode === _ccsg.ParticleSystem.Mode.RADIUS) { // or Mode B: radius movement var locModeB = this.modeB; From cd98111312dad060bed8a1e4e122cf58dcad7dc4 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 30 Nov 2016 14:18:26 +0800 Subject: [PATCH 03/12] Fixed a dead loop when the file texture uuid is undefined for fireball/issues/4822 --- cocos2d/particle/CCParticleSystem.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cocos2d/particle/CCParticleSystem.js b/cocos2d/particle/CCParticleSystem.js index 86c88cff68..18a77a61fd 100644 --- a/cocos2d/particle/CCParticleSystem.js +++ b/cocos2d/particle/CCParticleSystem.js @@ -918,6 +918,10 @@ var ParticleSystem = cc.Class({ // so use the texutreUuid instead of textureImageData if (content.textureUuid) { cc.AssetLibrary.queryAssetInfo(content.textureUuid, function (err, url, raw) { + if (err) { + cc.error(err); + return; + } self.texture = url; }); } From 5b08a52dcf59c28b7c01bec3f039aa34248e4523 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Fri, 2 Dec 2016 16:30:47 +0800 Subject: [PATCH 04/12] fix CCSystemEvent error --- cocos2d/core/event-manager/CCSystemEvent.js | 82 ++++++++++++--------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/cocos2d/core/event-manager/CCSystemEvent.js b/cocos2d/core/event-manager/CCSystemEvent.js index 881dedbd5a..546ab5c056 100644 --- a/cocos2d/core/event-manager/CCSystemEvent.js +++ b/cocos2d/core/event-manager/CCSystemEvent.js @@ -81,47 +81,57 @@ var SystemEvent = cc.Class({ this._super(type, callback, target, useCapture); // Keyboard - if (!keyboardListener && (type === EventType.KEY_DOWN || type === EventType.KEY_UP)) { - keyboardListener = cc.EventListener.create({ - event: cc.EventListener.KEYBOARD, - onKeyPressed: function (keyCode, event) { - event.type = EventType.KEY_DOWN; - if (CC_JSB) { - event.keyCode = keyCode; - event.isPressed = true; + if (type === EventType.KEY_DOWN || type === EventType.KEY_UP) { + if (!keyboardListener) { + keyboardListener = cc.EventListener.create({ + event: cc.EventListener.KEYBOARD, + onKeyPressed: function (keyCode, event) { + event.type = EventType.KEY_DOWN; + if (CC_JSB) { + event.keyCode = keyCode; + event.isPressed = true; + } + cc.systemEvent.dispatchEvent(event); + }, + onKeyReleased: function (keyCode, event) { + event.type = EventType.KEY_UP; + if (CC_JSB) { + event.keyCode = keyCode; + event.isPressed = false; + } + cc.systemEvent.dispatchEvent(event); } - cc.systemEvent.dispatchEvent(event); - }, - onKeyReleased: function (keyCode, event) { - event.type = EventType.KEY_UP; - if (CC_JSB) { - event.keyCode = keyCode; - event.isPressed = false; - } - cc.systemEvent.dispatchEvent(event); - } - }); - cc.eventManager.addListener(keyboardListener, 1); + }); + } + var hasKeyboardListener = cc.eventManager._getListeners(keyboardListener._listenerID); + if (!hasKeyboardListener) { + cc.eventManager.addListener(keyboardListener, 1); + } } // Acceleration - if (!accelerationListener && type === EventType.DEVICEMOTION) { - accelerationListener = cc.EventListener.create({ - event: cc.EventListener.ACCELERATION, - callback: function (accelEvent, event) { - event.type = EventType.DEVICEMOTION; - // fix android acc values are opposite - if (!CC_JSB && cc.sys.os === cc.sys.OS_ANDROID && - cc.sys.browserType !== cc.sys.BROWSER_TYPE_MOBILE_QQ) { - event.acc = cc.p(-accelEvent.x, -accelEvent.y); + if (type === EventType.DEVICEMOTION) { + if (accelerationListener) { + accelerationListener = cc.EventListener.create({ + event: cc.EventListener.ACCELERATION, + callback: function (accelEvent, event) { + event.type = EventType.DEVICEMOTION; + // fix android acc values are opposite + if (!CC_JSB && cc.sys.os === cc.sys.OS_ANDROID && + cc.sys.browserType !== cc.sys.BROWSER_TYPE_MOBILE_QQ) { + event.acc = cc.p(-accelEvent.x, -accelEvent.y); + } + else { + event.acc = cc.p(accelEvent.x, accelEvent.y); + } + cc.systemEvent.dispatchEvent(event); } - else { - event.acc = cc.p(accelEvent.x, accelEvent.y); - } - cc.systemEvent.dispatchEvent(event); - } - }); - cc.eventManager.addListener(accelerationListener, 1); + }); + } + var hasAccelerationListener = cc.eventManager._getListeners(accelerationListener._listenerID); + if (!hasAccelerationListener) { + cc.eventManager.addListener(accelerationListener, 1); + } } }, From 5cfc469e0b43df84020e488b42912fa3097cb6a8 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Mon, 5 Dec 2016 09:43:41 +0800 Subject: [PATCH 05/12] Repair loader._items.map to cc.loader._cache for enableAntiAlias --- cocos2d/core/platform/CCView.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/platform/CCView.js b/cocos2d/core/platform/CCView.js index c87b9f0c22..48156c5076 100644 --- a/cocos2d/core/platform/CCView.js +++ b/cocos2d/core/platform/CCView.js @@ -442,9 +442,9 @@ var View = cc._Class.extend({ } this._antiAliasEnabled = enabled; if(cc._renderType === cc.game.RENDER_TYPE_WEBGL) { - var map = cc.loader._items.map; - for (var key in map) { - var item = map[key]; + var cache = cc.loader._cache; + for (var key in cache) { + var item = cache[key]; var tex = item && item.content instanceof cc.Texture2D ? item.content : null; if (tex) { if (enabled) { From cb94f9a68384a2d0f5c2db92bd1e4c56c7afd2c0 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Tue, 6 Dec 2016 14:26:48 +0800 Subject: [PATCH 06/12] add hasEventListener for CCEventDispatcher --- cocos2d/core/event-manager/CCEventManager.js | 11 +++++++++++ cocos2d/core/event-manager/CCSystemEvent.js | 6 ++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/event-manager/CCEventManager.js b/cocos2d/core/event-manager/CCEventManager.js index 871cb52d05..972f43afa6 100644 --- a/cocos2d/core/event-manager/CCEventManager.js +++ b/cocos2d/core/event-manager/CCEventManager.js @@ -695,6 +695,17 @@ cc.eventManager = { return a - b; }, + /** + * !#en Query whether the specified event listener id has been added. + * !#zh 查询指定的事件 ID 是否存在 + * @method hasEventListener + * @param {String|Number} listenerID - The listener id. + * @return {Boolean} true or false + */ + hasEventListener: function (listenerID) { + return this._getListeners(listenerID) ? true : false; + }, + /** * !#en *

diff --git a/cocos2d/core/event-manager/CCSystemEvent.js b/cocos2d/core/event-manager/CCSystemEvent.js index 546ab5c056..363c1f7e76 100644 --- a/cocos2d/core/event-manager/CCSystemEvent.js +++ b/cocos2d/core/event-manager/CCSystemEvent.js @@ -103,8 +103,7 @@ var SystemEvent = cc.Class({ } }); } - var hasKeyboardListener = cc.eventManager._getListeners(keyboardListener._listenerID); - if (!hasKeyboardListener) { + if (!cc.eventManager.hasEventListener('__cc_keyboard')) { cc.eventManager.addListener(keyboardListener, 1); } } @@ -128,8 +127,7 @@ var SystemEvent = cc.Class({ } }); } - var hasAccelerationListener = cc.eventManager._getListeners(accelerationListener._listenerID); - if (!hasAccelerationListener) { + if (!cc.eventManager.hasEventListener('__cc_acceleration')) { cc.eventManager.addListener(accelerationListener, 1); } } From 55cfa7f7fbe835613ce4fac7111549acdd1fd6de Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Tue, 6 Dec 2016 16:30:13 +0800 Subject: [PATCH 07/12] update hasEventListener for CCEventDispatcher --- cocos2d/core/event-manager/CCEventManager.js | 2 +- cocos2d/core/event-manager/CCSystemEvent.js | 4 ++-- cocos2d/core/utils/base-node.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/event-manager/CCEventManager.js b/cocos2d/core/event-manager/CCEventManager.js index 972f43afa6..f75f08542e 100644 --- a/cocos2d/core/event-manager/CCEventManager.js +++ b/cocos2d/core/event-manager/CCEventManager.js @@ -703,7 +703,7 @@ cc.eventManager = { * @return {Boolean} true or false */ hasEventListener: function (listenerID) { - return this._getListeners(listenerID) ? true : false; + return !!this._getListeners(listenerID); }, /** diff --git a/cocos2d/core/event-manager/CCSystemEvent.js b/cocos2d/core/event-manager/CCSystemEvent.js index 363c1f7e76..a0ab1f4ee4 100644 --- a/cocos2d/core/event-manager/CCSystemEvent.js +++ b/cocos2d/core/event-manager/CCSystemEvent.js @@ -103,7 +103,7 @@ var SystemEvent = cc.Class({ } }); } - if (!cc.eventManager.hasEventListener('__cc_keyboard')) { + if (!cc.eventManager.hasEventListener(cc._EventListenerKeyboard.LISTENER_ID)) { cc.eventManager.addListener(keyboardListener, 1); } } @@ -127,7 +127,7 @@ var SystemEvent = cc.Class({ } }); } - if (!cc.eventManager.hasEventListener('__cc_acceleration')) { + if (!cc.eventManager.hasEventListener(cc._EventListenerAcceleration.LISTENER_ID)) { cc.eventManager.addListener(accelerationListener, 1); } } diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index 584941f7c7..5adbf65aee 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -792,12 +792,12 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ }, _onPreDestroy: function () { + cc.eventManager.removeListeners(this); if (CC_JSB) { this._sgNode.release(); this._sgNode._entity = null; this._sgNode = null; } - cc.eventManager.removeListeners(this); for (var i = 0, len = this.__eventTargets.length; i < len; ++i) { var target = this.__eventTargets[i]; target && target.targetOff(this); From ca72d3c46ae3c0207a63b7688d0b7210e9b028ad Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Wed, 7 Dec 2016 10:59:49 +0800 Subject: [PATCH 08/12] fix page view error for fireball/issues/4758 --- cocos2d/core/components/CCScrollView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCScrollView.js b/cocos2d/core/components/CCScrollView.js index 73c83a2193..31b2d2e0f2 100644 --- a/cocos2d/core/components/CCScrollView.js +++ b/cocos2d/core/components/CCScrollView.js @@ -25,7 +25,7 @@ var NUMBER_OF_GATHERED_TOUCHES_FOR_MOVE_SPEED = 5; var OUT_OF_BOUNDARY_BREAKING_FACTOR = 0.05; -var EPSILON = 1e-7; +var EPSILON = 1e-4; var MOVEMENT_FACTOR = 0.7; var quintEaseOut = function(time) { From 3354816e87787a7af0dcf4384eee72ee7e787464 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 7 Dec 2016 15:22:36 +0800 Subject: [PATCH 09/12] fix richtext custom chinese font rendering issue --- cocos2d/core/components/CCRichText.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/components/CCRichText.js b/cocos2d/core/components/CCRichText.js index 51d0cc8005..2975a0f84b 100644 --- a/cocos2d/core/components/CCRichText.js +++ b/cocos2d/core/components/CCRichText.js @@ -346,10 +346,15 @@ var RichText = cc.Class({ this._sgNode.addChild(labelSegment); this._labelSegments.push(labelSegment); + //when lineHeight is less than the content size of labelSize + //in Web platform, the extra pixels will be trimed. + //so we need to set the overflow to clamp in JSB + //FIXME: label in jsb should be refactored to keep the behavior the same as web platform. if(CC_JSB) { labelSegment.setOverflow(1); var size = labelSegment.getContentSize(); - labelSegment.setContentSize(size.width, this.lineHeight); + labelSegment.enableWrap(false); + labelSegment.setDimensions(size.width, this.lineHeight); } return labelSegment; From 3254fd0fff6e1b92c9ecd14e34cce1d293677672 Mon Sep 17 00:00:00 2001 From: knoxHuang <821686174@qq.com> Date: Thu, 8 Dec 2016 14:02:09 +0800 Subject: [PATCH 10/12] fix jsb mask this._clippingStencil is null --- cocos2d/core/components/CCMask.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/components/CCMask.js b/cocos2d/core/components/CCMask.js index 861b4301c4..8081439251 100644 --- a/cocos2d/core/components/CCMask.js +++ b/cocos2d/core/components/CCMask.js @@ -322,8 +322,10 @@ if (CC_JSB) { Mask.prototype.__superOnDestroy = Base.prototype.onDestroy; Mask.prototype.onDestroy = function () { this.__superOnDestroy(); - this._clippingStencil.release(); - this._clippingStencil = null; + if (this._clippingStencil) { + this._clippingStencil.release(); + this._clippingStencil = null; + } }; } From cfc193f89418f3c4612c1fabbbc072418e6bc9bf Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Thu, 8 Dec 2016 14:02:32 +0800 Subject: [PATCH 11/12] preload fnt when loading scene --- cocos2d/core/assets/CCAsset.js | 17 ++++++++++++++--- cocos2d/core/assets/CCBitmapFont.js | 6 ++++++ cocos2d/core/label/CCSGLabel.js | 2 +- cocos2d/core/load-pipeline/uuid-loader.js | 9 +++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/assets/CCAsset.js b/cocos2d/core/assets/CCAsset.js index 7e5462744b..904d0469cc 100644 --- a/cocos2d/core/assets/CCAsset.js +++ b/cocos2d/core/assets/CCAsset.js @@ -102,6 +102,7 @@ cc.Asset = cc.Class({ * 在 lite 版的 Fireball 里,raw asset 并不仅仅是在 properties 里声明了 rawType 才有, * 而是每个 asset 都能指定自己的 raw file url。这些 url 就存在 _rawFiles 字段中。 * AssetLibrary 并不会帮你加载这些 url,除非你声明了 rawType。 + * 在 Creator 里,_rawFiles 保留了下来,为了复用 cocos 引擎原有实现,直接用 _rawFiles 来加载 Asset 在 import 之前的源文件。 * * @property _rawFiles * @type {String[]} @@ -152,8 +153,8 @@ cc.Asset = cc.Class({ * Create a new node using this asset in the scene.
* If this type of asset dont have its corresponding node type, this method should be null. * !#zh - * 使用该资产在场景中创建一个新节点。
- * 如果这类资产没有相应的节点类型,该方法应该是空的。 + * 使用该资源在场景中创建一个新节点。
+ * 如果这类资源没有相应的节点类型,该方法应该是空的。 * @method createNode * @param {Function} callback * @param {String} callback.error - null or the error info @@ -170,7 +171,17 @@ cc.Asset = cc.Class({ */ _setRawFiles: function (rawFiles) { this._rawFiles = rawFiles.length > 0 ? rawFiles : null; - } + }, + + /** + * Preload raw files when loading scene. + * + * @method _preloadRawFiles + * @param {Function} callback + * @param {Error} callback.error + * @private + */ + _preloadRawFiles: null, }); module.exports = cc.Asset; diff --git a/cocos2d/core/assets/CCBitmapFont.js b/cocos2d/core/assets/CCBitmapFont.js index bae8a009e1..2842259221 100644 --- a/cocos2d/core/assets/CCBitmapFont.js +++ b/cocos2d/core/assets/CCBitmapFont.js @@ -46,6 +46,12 @@ var BitmapFont = cc.Class({ fontSize: { default: -1 } + }, + + _preloadRawFiles: function (done) { + // preload fnt file. (texture already loaded in properties) + var fntUrl = this.rawUrl; + cc.loader.load({ id: fntUrl, ignoreMaxConcurrency: true }, done); } }); diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 10520d0288..cf95a2a4b8 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -1140,8 +1140,8 @@ cc.BMFontHelper = { _setBMFontFile: function(filename, textureUrl) { if (filename) { this._fontHandle = filename; - var self = this; if (this._labelType === _ccsg.Label.Type.BMFont) { + var self = this; this._resetBMFont(); cc.loader.load(this._fontHandle, function(err, config) { diff --git a/cocos2d/core/load-pipeline/uuid-loader.js b/cocos2d/core/load-pipeline/uuid-loader.js index e4d9360fed..e86aa164f5 100644 --- a/cocos2d/core/load-pipeline/uuid-loader.js +++ b/cocos2d/core/load-pipeline/uuid-loader.js @@ -92,6 +92,15 @@ function loadDepends (pipeline, item, asset, tdInfo, deferredLoadRawAssetsInRunt propList.push(tdInfo.rawProp); depends.push(item.url); } + // preload raw files + if (asset._preloadRawFiles) { + var finalCallback = callback; + callback = function () { + asset._preloadRawFiles(function (err) { + finalCallback(err || null, asset); + }); + }; + } // fast path if (depends.length === 0) { asset._uuid = uuid; From 1fb594a2e46f8b9f392b0cac962841fda0e1d2d5 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Thu, 8 Dec 2016 15:52:21 +0800 Subject: [PATCH 12/12] add paramater of Director._loadSceneByUuid --- cocos2d/core/CCDirector.js | 39 +++++++++++++++++++++++++++++--------- jsb/jsb-director.js | 39 +++++++++++++++++++++++++++++--------- 2 files changed, 60 insertions(+), 18 deletions(-) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index de7056bd87..c1dc2639d5 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -796,35 +796,56 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ * @param {String} uuid - the uuid of the scene asset to load * @param {Function} [onLaunched] * @param {Function} [onUnloaded] + * @param {Boolean} [dontRunScene] - Just download and initialize the scene but will not launch it, + * only take effect in the Editor. * @private */ - _loadSceneByUuid: function (uuid, onLaunched, onUnloaded) { + _loadSceneByUuid: function (uuid, onLaunched, onUnloaded, dontRunScene) { + if (CC_EDITOR) { + if (typeof onLaunched === 'boolean') { + dontRunScene = onLaunched; + onLaunched = null; + } + if (typeof onUnloaded === 'boolean') { + dontRunScene = onUnloaded; + onUnloaded = null; + } + } //cc.AssetLibrary.unloadAsset(uuid); // force reload cc.AssetLibrary.loadAsset(uuid, function (error, sceneAsset) { var self = cc.director; self._loadingScene = ''; - var scene; if (error) { error = 'Failed to load scene: ' + error; cc.error(error); - if (CC_DEV) { - console.assert(false, error); - } } else { if (sceneAsset instanceof cc.SceneAsset) { - scene = sceneAsset.scene; + var scene = sceneAsset.scene; scene._id = sceneAsset._uuid; scene._name = sceneAsset._name; - self.runSceneImmediate(scene, onUnloaded, onLaunched); + if (CC_EDITOR) { + if (!dontRunScene) { + self.runSceneImmediate(scene, onUnloaded, onLaunched); + } + else { + scene._load(); + if (onLaunched) { + onLaunched(null, scene); + } + } + } + else { + self.runSceneImmediate(scene, onUnloaded, onLaunched); + } + return; } else { error = 'The asset ' + uuid + ' is not a scene'; cc.error(error); - scene = null; } } - if (error && onLaunched) { + if (onLaunched) { onLaunched(error); } }); diff --git a/jsb/jsb-director.js b/jsb/jsb-director.js index 88a5463a10..4d55bc3b97 100644 --- a/jsb/jsb-director.js +++ b/jsb/jsb-director.js @@ -328,35 +328,56 @@ cc.js.mixin(cc.director, { * @param {String} uuid - the uuid of the scene asset to load * @param {Function} [onLaunched] * @param {Function} [onUnloaded] + * @param {Boolean} [dontRunScene] - Just download and initialize the scene but will not launch it, + * only take effect in the Editor. * @private */ - _loadSceneByUuid: function (uuid, onLaunched, onUnloaded) { + _loadSceneByUuid: function (uuid, onLaunched, onUnloaded, dontRunScene) { + if (CC_EDITOR) { + if (typeof onLaunched === 'boolean') { + dontRunScene = onLaunched; + onLaunched = null; + } + if (typeof onUnloaded === 'boolean') { + dontRunScene = onUnloaded; + onUnloaded = null; + } + } //cc.AssetLibrary.unloadAsset(uuid); // force reload cc.AssetLibrary.loadAsset(uuid, function (error, sceneAsset) { var self = cc.director; self._loadingScene = ''; - var scene; if (error) { error = 'Failed to load scene: ' + error; cc.error(error); - if (CC_DEV) { - console.assert(false, error); - } } else { if (sceneAsset instanceof cc.SceneAsset) { - scene = sceneAsset.scene; + var scene = sceneAsset.scene; scene._id = sceneAsset._uuid; scene._name = sceneAsset._name; - self.runSceneImmediate(scene, onUnloaded, onLaunched); + if (CC_EDITOR) { + if (!dontRunScene) { + self.runSceneImmediate(scene, onUnloaded, onLaunched); + } + else { + scene._load(); + if (onLaunched) { + onLaunched(null, scene); + } + } + } + else { + self.runSceneImmediate(scene, onUnloaded, onLaunched); + } + return; } else { error = 'The asset ' + uuid + ' is not a scene'; cc.error(error); - scene = null; } } - if (error && onLaunched) { + if (onLaunched) { onLaunched(error); } });