|
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};
|
@@ -838,9 +840,9 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{
|
838 | 840 | //fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact)
|
839 | 841 | // and at the same time reorder descedants and the quads to the right index
|
840 | 842 | //if (cc.renderContextType == cc.WEBGL) {
|
841 |
| - for (i = 0; i < this._children.length; i++) { |
842 |
| - index = this._updateAtlasIndex(this._children[i], index); |
843 |
| - } |
| 843 | + for (i = 0; i < this._children.length; i++) { |
| 844 | + index = this._updateAtlasIndex(this._children[i], index); |
| 845 | + } |
844 | 846 | //}
|
845 | 847 | }
|
846 | 848 |
|
|
0 commit comments