25
25
****************************************************************************/
26
26
27
27
28
-
29
28
/**
30
29
* @constant
31
30
* @type Number
@@ -118,7 +117,6 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{
118
117
curIndex ++ ;
119
118
needNewIndex = false ;
120
119
}
121
-
122
120
for ( var i = 0 ; i < pArray . length ; i ++ ) {
123
121
var child = pArray [ i ] ;
124
122
if ( needNewIndex && child . getZOrder ( ) >= 0 ) {
@@ -150,17 +148,21 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{
150
148
} ,
151
149
152
150
_swap :function ( oldIndex , newIndex ) {
153
- var quads = this . _textureAtlas . getQuads ( ) ;
154
- var tempItem = this . _descendants [ oldIndex ] ;
155
- var tempIteQuad = quads [ oldIndex ] ;
156
-
157
- //update the index of other swapped item
158
- this . _descendants [ newIndex ] . setAtlasIndex ( oldIndex ) ;
151
+ if ( ( this . _descendants . length >= 2 ) && newIndex < this . _descendants . length ) {
152
+ if ( oldIndex == - 1 ) {
153
+ oldIndex = this . _descendants . length - 1 ;
154
+ }
155
+ var quads = this . _textureAtlas . getQuads ( ) ;
156
+ var tempItem = this . _descendants [ oldIndex ] ;
157
+ var tempIteQuad = quads [ oldIndex ] ;
159
158
160
- this . _descendants [ oldIndex ] = this . _descendants [ newIndex ] ;
161
- quads [ oldIndex ] = quads [ newIndex ] ;
162
- this . _descendants [ newIndex ] = tempItem ;
163
- quads [ newIndex ] = tempIteQuad ;
159
+ //update the index of other swapped item
160
+ this . _descendants [ newIndex ] . setAtlasIndex ( oldIndex ) ;
161
+ this . _descendants [ oldIndex ] = this . _descendants [ newIndex ] ;
162
+ quads [ oldIndex ] = quads [ newIndex ] ;
163
+ this . _descendants [ newIndex ] = tempItem ;
164
+ quads [ newIndex ] = tempIteQuad ;
165
+ }
164
166
} ,
165
167
166
168
// IMPORTANT XXX IMPORTNAT:
@@ -610,7 +612,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{
610
612
* @param {Number } dst
611
613
*/
612
614
setBlendFunc :function ( src , dst ) {
613
- if ( arguments . length == 1 )
615
+ if ( arguments . length == 1 )
614
616
this . _blendFunc = src ;
615
617
else
616
618
this . _blendFunc = { src :src , dst :dst } ;
@@ -822,8 +824,7 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{
822
824
j = i - 1 ;
823
825
824
826
//continue moving element downwards while zOrder is smaller or when zOrder is the same but orderOfArrival is smaller
825
- while ( j >= 0 && ( tempItem . getZOrder ( ) < this . _children [ j ] . getZOrder ( ) ||
826
- ( tempItem . getZOrder ( ) == this . _children [ j ] . getZOrder ( ) && tempItem . getOrderOfArrival ( ) < this . _children [ j ] . getOrderOfArrival ( ) ) ) ) {
827
+ while ( j >= 0 && ( tempItem . getZOrder ( ) < this . _children [ j ] . getZOrder ( ) || ( tempItem . getZOrder ( ) == this . _children [ j ] . getZOrder ( ) && tempItem . getOrderOfArrival ( ) < this . _children [ j ] . getOrderOfArrival ( ) ) ) ) {
827
828
this . _children [ j + 1 ] = this . _children [ j ] ;
828
829
j -- ;
829
830
}
@@ -838,11 +839,11 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{
838
839
var index = 0 ;
839
840
//fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact)
840
841
// and at the same time reorder descedants and the quads to the right index
841
- if ( cc . renderContextType == cc . WEBGL ) {
842
- for ( i = 0 ; i < this . _children . length ; i ++ ) {
843
- index = this . _updateAtlasIndex ( this . _children [ i ] , index ) ;
844
- }
842
+ //if (cc.renderContextType == cc.WEBGL) {
843
+ for ( i = 0 ; i < this . _children . length ; i ++ ) {
844
+ index = this . _updateAtlasIndex ( this . _children [ i ] , index ) ;
845
845
}
846
+ //}
846
847
}
847
848
848
849
this . _reorderChildDirty = false ;
0 commit comments