diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index f501ba9975..6d219df7ea 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -513,7 +513,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ // Re-attach or replace persist nodes for (id in persistNodes) { node = persistNodes[id]; - var existNode = scene.getChildByName(node.name); + var existNode = scene.getChildByUuid(id); // Scene contains the persist node, should not reattach, should update the persist node if (existNode) { persistNodes[id] = existNode; diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index c455dc313b..60e27474a2 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -976,6 +976,26 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ return null; }, + /** + * Returns a child from the container given its uuid + * @method getChildByUuid + * @param {String} uuid - The uuid to find the child node. + * @return {Node} a Node whose uuid equals to the input parameter + */ + getChildByUuid: function(uuid){ + if(!uuid){ + cc.log("Invalid uuid"); + return null; + } + + var locChildren = this._children; + for(var i = 0, len = locChildren.length; i < len; i++){ + if(locChildren[i]._id === uuid) + return locChildren[i]; + } + return null; + }, + /** * Returns a child from the container given its name * @method getChildByName diff --git a/jsb/jsb-director.js b/jsb/jsb-director.js index 60dad7be5b..3b4abbe1ab 100644 --- a/jsb/jsb-director.js +++ b/jsb/jsb-director.js @@ -136,7 +136,7 @@ cc.js.mixin(cc.director, { // Re-attach persist nodes for (id in persistNodes) { node = persistNodes[id]; - var existNode = scene.getChildByName(node.name); + var existNode = scene.getChildByUuid(id); // Scene contains the persist node, should not reattach, should update the persist node if (existNode) { persistNodes[id] = existNode;