From 6a9b1e67388c7644c52dff2579f4bc70ed2f5cf9 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 9 Mar 2016 17:06:54 +0800 Subject: [PATCH 1/8] Fix EVENT_AFTER_SCENE_LAUNCH not fired isse --- cocos2d/core/CCDirector.js | 2 +- jsb/jsb-director.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 1985bed3d1..4db5380964 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -539,8 +539,8 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ if (onLaunched) { onLaunched(null, scene); - this.emit(cc.Director.EVENT_AFTER_SCENE_LAUNCH, scene); } + this.emit(cc.Director.EVENT_AFTER_SCENE_LAUNCH, scene); }, /** diff --git a/jsb/jsb-director.js b/jsb/jsb-director.js index f572f4be95..adfd678125 100644 --- a/jsb/jsb-director.js +++ b/jsb/jsb-director.js @@ -151,8 +151,8 @@ cc.js.mixin(cc.director, { if (onLaunched) { onLaunched(null, scene); - this.emit(cc.Director.EVENT_AFTER_SCENE_LAUNCH, scene); } + this.emit(cc.Director.EVENT_AFTER_SCENE_LAUNCH, scene); }, /** From 195ed922f803a05987e25f84dcc8ad92f79173a9 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Wed, 9 Mar 2016 18:08:27 +0800 Subject: [PATCH 2/8] Fix downloadText won't return error issue --- jsb/jsb-loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsb/jsb-loader.js b/jsb/jsb-loader.js index f425537841..388d513451 100644 --- a/jsb/jsb-loader.js +++ b/jsb/jsb-loader.js @@ -41,7 +41,7 @@ function downloadText (item, callback) { url = cc.Pipeline.UrlResolver.getRawUrl(url); var result = jsb.fileUtils.getStringFromFile(url); - if (typeof result === 'string') { + if (result && typeof result === 'string') { callback(null, result); } else { From 201bf96706644e1c92c2ea6d5747b67434e27302 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Wed, 9 Mar 2016 19:53:12 +0800 Subject: [PATCH 3/8] fix jsb overflow none --- cocos2d/core/editbox/CCSGEditBox.js | 4 ++-- cocos2d/core/label/CCSGLabel.js | 4 ++-- jsb/jsb-label.js | 22 +++++++++++++++++----- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/cocos2d/core/editbox/CCSGEditBox.js b/cocos2d/core/editbox/CCSGEditBox.js index 05858a9604..3ddd557ed2 100644 --- a/cocos2d/core/editbox/CCSGEditBox.js +++ b/cocos2d/core/editbox/CCSGEditBox.js @@ -742,8 +742,8 @@ _ccsg.EditBox = _ccsg.Node.extend({ _updateEditBoxSize: function(size, height) { this._oldSetContentSize(size, height); - var newWidth = size.width || size; - var newHeight = size.height || height; + var newWidth = (typeof size.width === 'number') ? size.width : size; + var newHeight = (typeof size.height === 'number') ? size.height : height; this._updateBackgroundSpriteSize(newWidth, newHeight); this._nativeControl.setSize(newWidth, newHeight); diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 26404e359a..b9f1b0fefa 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -632,8 +632,8 @@ cc.BMFontHelper = { }, _setDimensions: function(size, height) { - var newWidth = size.width || size; - var newHeight = size.height || height; + var newWidth = (typeof size.width === 'number') ? size.width : size; + var newHeight = (typeof size.height === 'number') ? size.height : height; _ccsg.Node.prototype.setContentSize.call(this, size, height); diff --git a/jsb/jsb-label.js b/jsb/jsb-label.js index 1c36d20923..06fc931b55 100644 --- a/jsb/jsb-label.js +++ b/jsb/jsb-label.js @@ -45,6 +45,16 @@ if (!jsbLabel.prototype.setOverflow) { } if (!jsbLabel.prototype.getOverflow) { jsbLabel.prototype.getOverflow = function(){}; + +//fix jsb system font overflow +jsbLabel.prototype._setOverflow = jsbLabel.prototype.setOverflow; +jsbLabel.prototype.setOverflow = function(overflow) { + this._overFlow = overflow; + this._setOverflow(this._overFlow); +} + +jsbLabel.prototype.getOverflow = function() { + return this._overFlow; } if (!jsbLabel.prototype.isSystemFontUsed) { @@ -98,12 +108,14 @@ jsbLabel.prototype.getTTFConfig = function () { }; jsbLabel.prototype.setContentSize = function (size, height) { - if(height !== undefined){ - this.setDimensions(size, height); - } - else{ - this.setDimensions(size.width, size.height); + var newWidth = (typeof size.width === 'number') ? size.width : size; + var newHeight = (typeof size.height === 'number') ? size.height : height; + + if(this.getOverflow() === cc.Label.Overflow.NONE) { + newWidth = 0; + newHeight = 0; } + this.setDimensions(newWidth, newHeight); }; jsbLabel.prototype.setFontFileOrFamily = function (fontHandle) { From 0666f6b19f5216ddb1b86f72ce659df60a78ada2 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Thu, 10 Mar 2016 10:22:15 +0800 Subject: [PATCH 4/8] fix parsing error --- jsb/jsb-label.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/jsb/jsb-label.js b/jsb/jsb-label.js index 06fc931b55..4369f282e5 100644 --- a/jsb/jsb-label.js +++ b/jsb/jsb-label.js @@ -45,17 +45,18 @@ if (!jsbLabel.prototype.setOverflow) { } if (!jsbLabel.prototype.getOverflow) { jsbLabel.prototype.getOverflow = function(){}; +} //fix jsb system font overflow jsbLabel.prototype._setOverflow = jsbLabel.prototype.setOverflow; jsbLabel.prototype.setOverflow = function(overflow) { this._overFlow = overflow; this._setOverflow(this._overFlow); -} +}; jsbLabel.prototype.getOverflow = function() { return this._overFlow; -} +}; if (!jsbLabel.prototype.isSystemFontUsed) { jsbLabel.prototype.isSystemFontUsed = function() { @@ -103,6 +104,7 @@ jsbLabel.prototype.setTTFConfig = function (config) { this._setTTFConfig(config); this._ttfConfig = config; }; + jsbLabel.prototype.getTTFConfig = function () { return this._ttfConfig; }; From 0c92f2182d2971a10e9fa7854694dc9efbda3884 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 10 Mar 2016 14:44:08 +0800 Subject: [PATCH 5/8] Add cleanup logic to base node --- cocos2d/core/utils/base-node.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index 75d0749f44..3e8f4931fb 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -941,12 +941,10 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ * @method cleanup */ cleanup: function () { - //// actions - //this.stopAllActions(); - //this.unscheduleAllCallbacks(); - // - //// event - //cc.eventManager.removeListeners(this); + // actions + cc.director.getActionManager().removeAllActionsFromTarget(this); + // event + cc.eventManager.removeListeners(this); // children var i, len = this._children.length, node; From d558cf7bc7d6d9f988ad9070685d9ad9f147fb30 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 10 Mar 2016 16:15:53 +0800 Subject: [PATCH 6/8] Avoid a flash of last scene after loading a new scene --- cocos2d/core/CCDirector.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 4db5380964..d8ed84957d 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -540,6 +540,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ if (onLaunched) { onLaunched(null, scene); } + cc.renderer.clear(); this.emit(cc.Director.EVENT_AFTER_SCENE_LAUNCH, scene); }, From ef028c3385d4cb0de867c13d2581a878391aaf67 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 10 Mar 2016 16:16:17 +0800 Subject: [PATCH 7/8] Avoid duplicated callback invocation in cc.loader --- cocos2d/core/load-pipeline/CCLoader.js | 32 ++++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/cocos2d/core/load-pipeline/CCLoader.js b/cocos2d/core/load-pipeline/CCLoader.js index 1e5ff7e3ae..1dee19afc4 100644 --- a/cocos2d/core/load-pipeline/CCLoader.js +++ b/cocos2d/core/load-pipeline/CCLoader.js @@ -144,10 +144,14 @@ JS.mixin(cc.loader, { singleRes = true; } // Return directly if no resources - if (resources.length === 0 && completeCallback) { - callInNextTick(function () { - completeCallback.call(self, null, self._items); - }); + if (resources.length === 0) { + if (completeCallback) { + callInNextTick(function () { + completeCallback.call(self, null, self._items); + completeCallback = null; + }); + } + return; } // Resolve callback @@ -181,6 +185,7 @@ JS.mixin(cc.loader, { completeCallback.call(self, error, self._items); } } + completeCallback = null; } // Add loaded listeners @@ -205,14 +210,17 @@ JS.mixin(cc.loader, { if (totalCount === completedCount) { var id = resources[0].id || resources[0]; var result = this._items.map[id]; - callInNextTick(function () { - if (singleRes) { - completeCallback.call(self, result.error, result.content); - } - else { - completeCallback.call(self, null, self._items); - } - }); + if (completeCallback) { + callInNextTick(function () { + if (singleRes) { + completeCallback.call(self, result.error, result.content); + } + else { + completeCallback.call(self, null, self._items); + } + completeCallback = null; + }); + } } else { this.flowIn(resources); From c26dd4b9dfe42cbfc4b708617b8838473f8ad78c Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 10 Mar 2016 16:17:01 +0800 Subject: [PATCH 8/8] Avoid creating duplicated sprite batch node for bmfont Label --- cocos2d/core/label/CCSGLabel.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index b9f1b0fefa..94f855c41f 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -1088,7 +1088,6 @@ cc.BMFontHelper = { this._fontHandle = filename; var self = this; if (this._labelType === _ccsg.Label.Type.BMFont) { - this._resetBMFont(); var texture; @@ -1113,7 +1112,9 @@ cc.BMFontHelper = { self.emit("load"); }, self); } else { - self._createSpriteBatchNode(texture); + if (!self._spriteBatchNode) { + self._createSpriteBatchNode(texture); + } } }); }