Skip to content

Commit 086cb20

Browse files
author
pandamicro
committed
Remove useless code in Sprite for old batch node
1 parent cef6a7b commit 086cb20

File tree

3 files changed

+9
-115
lines changed

3 files changed

+9
-115
lines changed

CCDebugger.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ cc._LogInfos = {
6868
Node_resumeSchedulerAndActions: "resumeSchedulerAndActions is deprecated, please use resume instead.",
6969
Node_pauseSchedulerAndActions: "pauseSchedulerAndActions is deprecated, please use pause instead.",
7070
Node__arrayMakeObjectsPerformSelector: "Unknown callback function",
71-
Node_reorderChild: "child must be non-null",
71+
Node_reorderChild: "cc.Node.reorderChild(): child must be non-null",
72+
Node_reorderChild_2: "cc.Node.reorderChild(): this child is not in children list",
7273
Node_runAction: "cc.Node.runAction(): action must be non-null",
7374
Node_schedule: "callback function must be non-null",
7475
Node_schedule_2: "interval must be positive",
@@ -119,7 +120,6 @@ cc._LogInfos = {
119120
animationCache__parseVersion2_2: "cocos2d: cc.AnimationCache: Animation '%s' refers to frame '%s' which is not currently in the cc.SpriteFrameCache. This frame will not be added to the animation.",
120121
animationCache_addAnimations_2: "cc.AnimationCache.addAnimations(): Invalid texture file name",
121122

122-
Sprite_reorderChild: "cc.Sprite.reorderChild(): this child is not in children list",
123123
Sprite_ignoreAnchorPointForPosition: "cc.Sprite.ignoreAnchorPointForPosition(): it is invalid in cc.Sprite when using SpriteBatchNode",
124124
Sprite_setDisplayFrameWithAnimationName: "cc.Sprite.setDisplayFrameWithAnimationName(): Frame not found",
125125
Sprite_setDisplayFrameWithAnimationName_2: "cc.Sprite.setDisplayFrameWithAnimationName(): Invalid frame index",
@@ -130,7 +130,6 @@ cc._LogInfos = {
130130
Sprite_initWithSpriteFrameName1: " is null, please check.",
131131
Sprite_initWithFile: "cc.Sprite.initWithFile(): filename should be non-null",
132132
Sprite_setDisplayFrameWithAnimationName_3: "cc.Sprite.setDisplayFrameWithAnimationName(): animationName must be non-null",
133-
Sprite_reorderChild_2: "cc.Sprite.reorderChild(): child should be non-null",
134133
Sprite_addChild: "cc.Sprite.addChild(): cc.Sprite only supports cc.Sprites as children when using cc.SpriteBatchNode",
135134
Sprite_addChild_2: "cc.Sprite.addChild(): cc.Sprite only supports a sprite using same texture as children when using cc.SpriteBatchNode",
136135
Sprite_addChild_3: "cc.Sprite.addChild(): child should be non-null",

cocos2d/core/base-nodes/CCNode.js

+7
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,13 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
13601360
*/
13611361
reorderChild: function (child, zOrder) {
13621362
cc.assert(child, cc._LogInfos.Node_reorderChild);
1363+
if (this._children.indexOf(child) === -1) {
1364+
cc.log(cc._LogInfos.Node_reorderChild_2);
1365+
return;
1366+
}
1367+
if (zOrder === child.zIndex) {
1368+
return;
1369+
}
13631370
cc.renderer.childrenOrderDirty = this._reorderChildDirty = true;
13641371
child.arrivalOrder = cc.s_globalOrderOfArrival;
13651372
cc.s_globalOrderOfArrival++;

cocos2d/core/sprites/CCSprite.js

-112
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,6 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
276276
* @param {cc.SpriteBatchNode} batchNode
277277
*/
278278
useBatchNode: function (batchNode) {
279-
this.textureAtlas = batchNode.getTextureAtlas(); // weak ref
280-
this._batchNode = batchNode;
281279
},
282280

283281
/**
@@ -299,94 +297,10 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
299297
this._renderCmd.setDirtyFlag(cc.Node._dirtyFlags.transformDirty);
300298
},
301299

302-
/**
303-
* Sort all children of this sprite node.
304-
* @override
305-
*/
306-
sortAllChildren: function () {
307-
if (this._reorderChildDirty) {
308-
var _children = this._children;
309-
310-
cc.Node.prototype.sortAllChildren.call(this);
311-
312-
if (this._batchNode) {
313-
this._arrayMakeObjectsPerformSelector(_children, cc.Node._stateCallbackType.sortAllChildren);
314-
}
315-
316-
//don't need to check children recursively, that's done in visit of each child
317-
this._reorderChildDirty = false;
318-
}
319-
320-
},
321-
322-
/**
323-
* Reorders a child according to a new z value. (override cc.Node )
324-
* @param {cc.Node} child
325-
* @param {Number} zOrder
326-
* @override
327-
*/
328-
reorderChild: function (child, zOrder) {
329-
cc.assert(child, cc._LogInfos.Sprite_reorderChild_2);
330-
if (this._children.indexOf(child) === -1) {
331-
cc.log(cc._LogInfos.Sprite_reorderChild);
332-
return;
333-
}
334-
335-
if (zOrder === child.zIndex)
336-
return;
337-
338-
if (this._batchNode && !this._reorderChildDirty) {
339-
this._setReorderChildDirtyRecursively();
340-
this._batchNode.reorderBatch(true);
341-
}
342-
cc.Node.prototype.reorderChild.call(this, child, zOrder);
343-
},
344-
345-
/**
346-
* Removes a child from the sprite.
347-
* @param child
348-
* @param cleanup whether or not cleanup all running actions
349-
* @override
350-
*/
351-
removeChild: function (child, cleanup) {
352-
if (this._batchNode)
353-
this._batchNode.removeSpriteFromAtlas(child);
354-
cc.Node.prototype.removeChild.call(this, child, cleanup);
355-
},
356-
357-
/**
358-
* Removes all children from the container.
359-
* @param cleanup whether or not cleanup all running actions
360-
* @override
361-
*/
362-
removeAllChildren: function (cleanup) {
363-
var locChildren = this._children, locBatchNode = this._batchNode;
364-
if (locBatchNode && locChildren != null) {
365-
for (var i = 0, len = locChildren.length; i < len; i++)
366-
locBatchNode.removeSpriteFromAtlas(locChildren[i]);
367-
}
368-
369-
cc.Node.prototype.removeAllChildren.call(this, cleanup);
370-
this._hasChildren = false;
371-
},
372-
373300
//
374301
// cc.Node property overloads
375302
//
376303

377-
/**
378-
* Sets whether ignore anchor point for positioning
379-
* @param {Boolean} relative
380-
* @override
381-
*/
382-
ignoreAnchorPointForPosition: function (relative) {
383-
if (this._batchNode) {
384-
cc.log(cc._LogInfos.Sprite_ignoreAnchorPointForPosition);
385-
return;
386-
}
387-
cc.Node.prototype.ignoreAnchorPointForPosition.call(this, relative);
388-
},
389-
390304
/**
391305
* Sets whether the sprite should be flipped horizontally or not.
392306
* @param {Boolean} flippedX true if the sprite should be flipped horizontally, false otherwise.
@@ -494,18 +408,6 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
494408
return this._batchNode;
495409
},
496410

497-
_setReorderChildDirtyRecursively: function () {
498-
//only set parents flag the first time
499-
if (!this._reorderChildDirty) {
500-
this._reorderChildDirty = true;
501-
var pNode = this._parent;
502-
while (pNode && pNode !== this._batchNode) {
503-
pNode._setReorderChildDirtyRecursively();
504-
pNode = pNode.parent;
505-
}
506-
}
507-
},
508-
509411
// CCTextureProtocol
510412
/**
511413
* Returns the texture of the sprite node
@@ -856,20 +758,6 @@ cc.Sprite = cc.Node.extend(/** @lends cc.Sprite# */{
856758
* layer.addChild(batch);
857759
*/
858760
setBatchNode: function (spriteBatchNode) {
859-
var _t = this;
860-
_t._batchNode = spriteBatchNode; // weak reference
861-
862-
// self render
863-
if (!_t._batchNode) {
864-
_t.atlasIndex = cc.Sprite.INDEX_NOT_INITIALIZED;
865-
_t.textureAtlas = null;
866-
_t._recursiveDirty = false;
867-
_t.dirty = false;
868-
} else {
869-
// using batch
870-
_t._transformToBatch = cc.affineTransformIdentity();
871-
_t.textureAtlas = _t._batchNode.getTextureAtlas(); // weak ref
872-
}
873761
},
874762

875763
// CCTextureProtocol

0 commit comments

Comments
 (0)