請問如何一口氣刪除多個節點by tag

用了removeChildByTag,但只能一個個刪除,我看過其中一個post,用removeChildrenByTag,但是好像是沒有這個function的,謝謝

cc.Class({
    extends: cc.Component,

    properties: {
       
      touchBeganX: cc.Label,
      touchBeganY: cc.Label,
      touchMovedX: cc.Label,
      touchMovedY: cc.Label,
      touchEndedX: cc.Label,
      touchEndedY: cc.Label,
      PenPrefab: cc.Prefab,

    },


DrawNewPen : function(location){

var newPen = cc.instantiate(this.PenPrefab);
                this.node.addChild(newPen,1,1001);
                newPen.setPosition(location.x,location.y)

},



nodeListener: function(){

     var self = this;
      var canvas = cc.find('Canvas')
        cc.eventManager.addListener({
            event: cc.EventListener.TOUCH_ONE_BY_ONE,

            onTouchBegan: function(touch, event) {
              
            var location = canvas.convertToNodeSpaceAR( touch.getLocation() );
              self.touchBeganX.string = location.x;

               self.touchBeganY.string = location.y;

            

                self.DrawNewPen(location);

                return true
            },
            onTouchMoved: function(touch, event) {
               

            var location = canvas.convertToNodeSpaceAR( touch.getLocation() );

                self.touchMovedX.string = location.x;
                self.touchMovedY.string = location.y;

  self.DrawNewPen(location);
                return true
            },
            onTouchEnded: function(touch, event) {
               
  var location = canvas.convertToNodeSpaceAR( touch.getLocation() );
                 self.touchEndedX.string = location.x;
                self.touchEndedY.string = location.y;

                
  self.DrawNewPen(location);
  
  self.node.removeChildByTag(1001);



                return true
            }
        }, self.node);





},

    // use this for initialization
    onLoad: function () {

this.nodeListener();
   
    },

  
});

push:cry:

push!!

push!!1

push

建议想想别的法子,因为tag这个属性说不定哪天就没了。。。。。(参考

[quote=“jare, post:11, topic:48965”]
因为 tag 是一个本该用 component 模拟的东西,实际上我都不希望有这个属性。tag 纯粹就是 cocos2d 的历史遗留产物,说不定哪天就没了……
[/quote])

1赞

I use other way to delete the children now. Very simple, Thanks 乱.码.啊

var penArray = [];

DrawNewPen : function(location){

var newPen = cc.instantiate(this.PenPrefab);
                this.node.addChild(newPen,1,1001);
                newPen.setPosition(location.x,location.y)
                penArray.push(newPen);

},

// when I need to remove children what I created, call this function

for (i = 0; i< penArray.length; i++){
      self.node.removeChild(penArray[i]);
  }
1赞