Skip to content

Commit

Permalink
Merge pull request cocos#1162 from natural-law/solve-example-error
Browse files Browse the repository at this point in the history
Solve the error effect of TiledMap example on native.
  • Loading branch information
jareguo authored Sep 30, 2016
2 parents a81471b + 5e58a29 commit 97be55e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cocos2d/core/components/CCRendererInSG.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var RendererInSG = cc.Class({
sgNode.retain();
}

// The replacement node used when this component disabled
// The replacement node used when this component disabled
this._plainNode = new _ccsg.Node();
if (CC_JSB) {
this._plainNode.retain();
Expand Down Expand Up @@ -107,9 +107,9 @@ var RendererInSG = cc.Class({
cc.warn('The same sgNode');
return;
}

// rebuild scene graph

// replace children
var children = replaced.getChildren().slice();
replaced.removeAllChildren(false);
Expand All @@ -122,7 +122,7 @@ var RendererInSG = cc.Class({
for (var i = 0, len = children.length; i < len; ++i) {
sgNode.addChild(children[i]);
}

// replace parent
var parentNode = replaced.getParent();
if (parentNode) {
Expand All @@ -131,6 +131,16 @@ var RendererInSG = cc.Class({
if ( !CC_JSB ) {
sgNode._arrivalOrder = replaced._arrivalOrder;
cc.renderer.childrenOrderDirty = parentNode._reorderChildDirty = true;
} else {
// update the arrival order of replaced sgNode
var parentEntity = this.node._parent;
if (parentEntity) {
var entityChildren = parentEntity._children;
var startIdx = this.node.getSiblingIndex();
for (i = startIdx + 1; i < entityChildren.length; i++) {
entityChildren[i]._sgNode.updateOrderOfArrival();
}
}
}
}
// replaced.release();
Expand Down

0 comments on commit 97be55e

Please sign in to comment.