@@ -703,53 +703,50 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{
703
703
704
704
_removeSpriteFromAtlasForCanvas :function ( sprite ) {
705
705
// Cleanup sprite. It might be reused (issue #569)
706
+ var delIndex = sprite . getAtlasIndex ( ) ;
706
707
sprite . setBatchNode ( null ) ;
707
708
var locDescendants = this . _descendants ;
708
709
var index = cc . ArrayGetIndexOfObject ( locDescendants , sprite ) ;
709
- if ( index != - 1 ) {
710
+ if ( index != - 1 )
710
711
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 ) ;
718
717
}
719
718
720
719
// remove children recursively
721
720
var children = sprite . getChildren ( ) ;
722
721
if ( children && children . length > 0 ) {
723
- for ( var i = 0 ; i < children . length ; i ++ )
722
+ for ( i = 0 ; i < children . length ; i ++ )
724
723
if ( children [ i ] )
725
724
this . removeSpriteFromAtlas ( children [ i ] ) ;
726
725
}
727
726
} ,
728
727
729
728
_removeSpriteFromAtlasForWebGL :function ( sprite ) {
729
+ var delIndex = sprite . getAtlasIndex ( ) ;
730
730
this . _textureAtlas . removeQuadAtIndex ( sprite . getAtlasIndex ( ) ) ; // remove from TextureAtlas
731
731
732
732
// Cleanup sprite. It might be reused (issue #569)
733
733
sprite . setBatchNode ( null ) ;
734
734
735
735
var locDescendants = this . _descendants ;
736
736
var index = cc . ArrayGetIndexOfObject ( locDescendants , sprite ) ;
737
- if ( index != - 1 ) {
737
+ if ( index != - 1 )
738
738
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 ) ;
747
744
}
748
745
749
746
// remove children recursively
750
747
var children = sprite . getChildren ( ) ;
751
748
if ( children && children . length > 0 ) {
752
- for ( var i = 0 ; i < children . length ; i ++ )
749
+ for ( i = 0 ; i < children . length ; i ++ )
753
750
if ( children [ i ] )
754
751
this . removeSpriteFromAtlas ( children [ i ] ) ;
755
752
}
0 commit comments