Skip to content

Commit 4297e23

Browse files
committed
Merge pull request cocos2d#1563 from dingpinglv/Iss4051_FixTMXLayerRemoveChild
Closed #4051: cc.TMXLayer.removeChild's bug has been fixed.
2 parents 70c4bee + aa75caf commit 4297e23

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

cocos2d/core/sprite_nodes/CCSpriteBatchNode.js

+16-19
Original file line numberDiff line numberDiff line change
@@ -703,53 +703,50 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{
703703

704704
_removeSpriteFromAtlasForCanvas:function (sprite) {
705705
// Cleanup sprite. It might be reused (issue #569)
706+
var delIndex = sprite.getAtlasIndex();
706707
sprite.setBatchNode(null);
707708
var locDescendants = this._descendants;
708709
var index = cc.ArrayGetIndexOfObject(locDescendants, sprite);
709-
if (index != -1) {
710+
if (index != -1)
710711
cc.ArrayRemoveObjectAtIndex(locDescendants, index);
711-
712-
// update all sprites beyond this one
713-
var len = locDescendants.length;
714-
for (; index < len; ++index) {
715-
var s = locDescendants[index];
716-
s.setAtlasIndex(s.getAtlasIndex() - 1);
717-
}
712+
var curChildren = this._children, i, selSprite;
713+
for(i = 0; i < curChildren.length; i++){
714+
selSprite = curChildren[i];
715+
if(selSprite.getAtlasIndex() > delIndex)
716+
selSprite.setAtlasIndex(selSprite.getAtlasIndex() - 1);
718717
}
719718

720719
// remove children recursively
721720
var children = sprite.getChildren();
722721
if (children && children.length > 0) {
723-
for (var i = 0; i < children.length; i++)
722+
for (i = 0; i < children.length; i++)
724723
if (children[i])
725724
this.removeSpriteFromAtlas(children[i]);
726725
}
727726
},
728727

729728
_removeSpriteFromAtlasForWebGL:function (sprite) {
729+
var delIndex = sprite.getAtlasIndex();
730730
this._textureAtlas.removeQuadAtIndex(sprite.getAtlasIndex()); // remove from TextureAtlas
731731

732732
// Cleanup sprite. It might be reused (issue #569)
733733
sprite.setBatchNode(null);
734734

735735
var locDescendants = this._descendants;
736736
var index = cc.ArrayGetIndexOfObject(locDescendants, sprite);
737-
if (index != -1) {
737+
if (index != -1)
738738
cc.ArrayRemoveObjectAtIndex(locDescendants, index);
739-
740-
// update all sprites beyond this one
741-
742-
var len = locDescendants.length;
743-
for (; index < len; ++index) {
744-
var s = locDescendants[index];
745-
s.setAtlasIndex(s.getAtlasIndex() - 1);
746-
}
739+
var curChildren = this._children, i, selSprite;
740+
for(i = 0; i < curChildren.length; i++){
741+
selSprite = curChildren[i];
742+
if(selSprite.getAtlasIndex() > delIndex)
743+
selSprite.setAtlasIndex(selSprite.getAtlasIndex() - 1);
747744
}
748745

749746
// remove children recursively
750747
var children = sprite.getChildren();
751748
if (children && children.length > 0) {
752-
for (var i = 0; i < children.length; i++)
749+
for (i = 0; i < children.length; i++)
753750
if (children[i])
754751
this.removeSpriteFromAtlas(children[i]);
755752
}

0 commit comments

Comments
 (0)