@@ -86,7 +86,8 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{
8686 for ( var index = 0 ; index < locDescendants . length ; index ++ ) {
8787 var obj = locDescendants [ index ] ;
8888 if ( obj && ( obj . getAtlasIndex ( ) >= z ) )
89- ++ i ;
89+ break ;
90+ ++ i ;
9091 }
9192 }
9293 this . _descendants = cc . ArrayAppendObjectToIndex ( locDescendants , child , i ) ;
@@ -703,50 +704,53 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{
703704
704705 _removeSpriteFromAtlasForCanvas :function ( sprite ) {
705706 // Cleanup sprite. It might be reused (issue #569)
706- var delIndex = sprite . getAtlasIndex ( ) ;
707707 sprite . setBatchNode ( null ) ;
708708 var locDescendants = this . _descendants ;
709709 var index = cc . ArrayGetIndexOfObject ( locDescendants , sprite ) ;
710- if ( index != - 1 )
710+ if ( index != - 1 ) {
711711 cc . ArrayRemoveObjectAtIndex ( locDescendants , index ) ;
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 ) ;
712+
713+ // update all sprites beyond this one
714+ var len = locDescendants . length ;
715+ for ( ; index < len ; ++ index ) {
716+ var s = locDescendants [ index ] ;
717+ s . setAtlasIndex ( s . getAtlasIndex ( ) - 1 ) ;
718+ }
717719 }
718720
719721 // remove children recursively
720722 var children = sprite . getChildren ( ) ;
721723 if ( children && children . length > 0 ) {
722- for ( i = 0 ; i < children . length ; i ++ )
724+ for ( var i = 0 ; i < children . length ; i ++ )
723725 if ( children [ i ] )
724726 this . removeSpriteFromAtlas ( children [ i ] ) ;
725727 }
726728 } ,
727729
728730 _removeSpriteFromAtlasForWebGL :function ( sprite ) {
729- var delIndex = sprite . getAtlasIndex ( ) ;
730731 this . _textureAtlas . removeQuadAtIndex ( sprite . getAtlasIndex ( ) ) ; // remove from TextureAtlas
731732
732733 // Cleanup sprite. It might be reused (issue #569)
733734 sprite . setBatchNode ( null ) ;
734735
735736 var locDescendants = this . _descendants ;
736737 var index = cc . ArrayGetIndexOfObject ( locDescendants , sprite ) ;
737- if ( index != - 1 )
738+ if ( index != - 1 ) {
738739 cc . ArrayRemoveObjectAtIndex ( locDescendants , index ) ;
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 ) ;
740+
741+ // update all sprites beyond this one
742+
743+ var len = locDescendants . length ;
744+ for ( ; index < len ; ++ index ) {
745+ var s = locDescendants [ index ] ;
746+ s . setAtlasIndex ( s . getAtlasIndex ( ) - 1 ) ;
747+ }
744748 }
745749
746750 // remove children recursively
747751 var children = sprite . getChildren ( ) ;
748752 if ( children && children . length > 0 ) {
749- for ( i = 0 ; i < children . length ; i ++ )
753+ for ( var i = 0 ; i < children . length ; i ++ )
750754 if ( children [ i ] )
751755 this . removeSpriteFromAtlas ( children [ i ] ) ;
752756 }
0 commit comments