Skip to content

Commit 987d051

Browse files
committed
Fixed cocos2d#2416: SpriteBatchNode needn't check texture when adding a child to it.
1 parent ef19901 commit 987d051

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

cocos2d/core/sprites/CCSpriteBatchNode.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -561,14 +561,8 @@ cc.SpriteBatchNode = cc.Node.extend(/** @lends cc.SpriteBatchNode# */{
561561
addChild: function (child, zOrder, tag) {
562562
cc.assert(child != null, cc._LogInfos.CCSpriteBatchNode_addChild_3);
563563

564-
if (!(child instanceof cc.Sprite)) {
565-
cc.log(cc._LogInfos.Sprite_addChild_4);
566-
return;
567-
}
568-
if (child.texture != this._renderCmd.getTexture()) {
569-
cc.log(cc._LogInfos.Sprite_addChild_5);
564+
if(!this._renderCmd.isValidChild(child))
570565
return;
571-
}
572566

573567
zOrder = (zOrder == null) ? child.zIndex : zOrder;
574568
tag = (tag == null) ? child.tag : tag;

cocos2d/core/sprites/CCSpriteBatchNodeCanvasRenderCmd.js

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636

3737
proto.checkAtlasCapacity = function(){};
3838

39+
proto.isValidChild = function(child){
40+
if (!(child instanceof cc.Sprite)) {
41+
cc.log(cc._LogInfos.Sprite_addChild_4);
42+
return false;
43+
}
44+
return true;
45+
};
46+
3947
proto.initWithTexture = function(texture, capacity){
4048
this._originalTexture = texture;
4149
this._texture = texture;

cocos2d/core/sprites/CCSpriteBatchNodeWebGLRenderCmd.js

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@
3434
var proto = cc.SpriteBatchNode.WebGLRenderCmd.prototype = Object.create(cc.Node.WebGLRenderCmd.prototype);
3535
proto.constructor = cc.SpriteBatchNode.WebGLRenderCmd;
3636

37+
proto.isValidChild = function(child){
38+
if (!(child instanceof cc.Sprite)) {
39+
cc.log(cc._LogInfos.Sprite_addChild_4);
40+
return false;
41+
}
42+
if (child.texture != this.getTexture()) {
43+
cc.log(cc._LogInfos.Sprite_addChild_5);
44+
return false;
45+
}
46+
return true;
47+
};
48+
3749
proto.rendering = function () {
3850
var node = this._node;
3951
if (this._textureAtlas.totalQuads === 0)

0 commit comments

Comments
 (0)