Merge pull request #488 from pandamicro/v1.0

Detect existing persist node by uuid
This commit is contained in:
Jare Guo
2016-03-17 11:55:32 +08:00
3 changed files with 22 additions and 2 deletions
+1 -1
View File
@@ -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;
+20
View File
@@ -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
+1 -1
View File
@@ -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;