From e0f3a360061f8453cc0c0727ff88110901c47b65 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Thu, 23 Jun 2016 18:43:00 +0800 Subject: [PATCH 1/3] fix unit test --- cocos2d/core/utils/base-node.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index 124e63aadb..d56eab9457 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -804,9 +804,13 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ this.__ignoreAnchor = false; }, - _onPreDestroy: CC_JSB && function () { - this._sgNode.release(); - this._sgNode = null; + _onPreDestroy: function () { + if (CC_JSB) { + this._sgNode.release(); + this._sgNode = null; + } + //cc.eventManager.removeListeners(this); + cc.director.off(cc.Director.EVENT_AFTER_UPDATE, this.sortAllChildren, this); }, _destruct: Misc.destructIgnoreId, From 2c9f152867e7323a799542608ea08d6d4b9d5370 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Fri, 24 Jun 2016 10:59:02 +0800 Subject: [PATCH 2/3] fine tune the api doc --- cocos2d/core/utils/base-node.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index d56eab9457..61106aa6dc 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -2096,17 +2096,20 @@ Misc.propertyDefine(BaseNode, SameNameGetSets, DiffNameGetSets); /** - * !#en position of node. - * !#zh 节点相对父节点的坐标。 + * !#en The local position in its parent's coordinate system.
+ * PS: The returned value is a copy of current position, so modification of the copy will not take effect for the actual position of the node. + * !#zh 节点相对父节点的坐标。
+ * 注意:返回值会是当前 position 的副本,所以对该副本所做的修改并不会影响节点的实际坐标。 * @property position * @type {Vec2} * @example - * node.position = new cc.Vec2(0, 0); + * node.position = new cc.Vec2(0, 0); // OK! + * node.position.addSelf(new cc.Vec2(1, 0)); // Invalid! */ /** - * !#en Scale of node. - * !#zh 节点缩放 + * !#en The local scale relative to the parent. + * !#zh 节点相对父节点的缩放。 * @property scale * @type {Number} * @example From c0585d676bd6d54e95ab903ccce4e0c6c23c4613 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Fri, 24 Jun 2016 14:09:17 +0800 Subject: [PATCH 3/3] use __eventTargets to automate unregister Scene events --- cocos2d/core/CCNode.js | 12 ------------ cocos2d/core/utils/base-node.js | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 82862e2266..f07ba3159a 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -463,9 +463,6 @@ var Node = cc.Class({ this._name = typeof name !== 'undefined' ? name : 'New Node'; this._activeInHierarchy = false; - // Support for ActionManager and EventManager - this.__instanceId = this._id || cc.ClassManager.getNewInstanceId(); - // cache component this._widget = null; @@ -475,15 +472,6 @@ var Node = cc.Class({ // Mouse event listener this._mouseListener = null; - /** - * Register all related EventTargets, - * all event callbacks will be removed in _onPreDestroy - * @property __eventTargets - * @type {EventTarget[]} - * @private - */ - this.__eventTargets = []; - // Retained actions for JSB if (CC_JSB) { this._retainedActions = []; diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index 61106aa6dc..4db2211606 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -802,6 +802,18 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ this._sizeProvider = null; this.__ignoreAnchor = false; + + // Support for ActionManager and EventManager + this.__instanceId = this._id || cc.ClassManager.getNewInstanceId(); + + /** + * Register all related EventTargets, + * all event callbacks will be removed in _onPreDestroy + * @property __eventTargets + * @type {EventTarget[]} + * @private + */ + this.__eventTargets = []; }, _onPreDestroy: function () { @@ -809,8 +821,11 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ this._sgNode.release(); this._sgNode = null; } - //cc.eventManager.removeListeners(this); - cc.director.off(cc.Director.EVENT_AFTER_UPDATE, this.sortAllChildren, this); + cc.eventManager.removeListeners(this); + for (var i = 0, len = this.__eventTargets.length; i < len; ++i) { + var target = this.__eventTargets[i]; + target && target.targetOff(this); + } }, _destruct: Misc.destructIgnoreId,