用了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();
},
});
