拿到所有子节点。
判断是不是子弹,子弹有组件bullet
重新开始,移除所有子弹
onBulletKilled: function (bullet) {
// 子弹 销毁的时候 回收到 对象池里面
this.bullet_pool.put(bullet);
// 和初始化时的方法一样,将节点放进对象池,这个方法会同时调用节点的 removeFromParent
},
remove_all_bullet(){
var children = this.node.children;
for (let i = children.length-1; i>=0; i--) {
//getComponent是获取这个子节点上面的组件,如果是子弹有脚本组件的,从而判断是不是子弹。
var js = children[i].getComponent('bullet');
if(js){
//移除子弹
this.onBulletKilled(children[i]);
}
}
},在update中输出 子节点数量 判断有没有移除成功
cc.log(this.node.children.length);
在子弹脚本中写,子弹跑出屏幕 自己消失 。
update(dt) {
if(game.isBgMove==true){
this.node.y = this.node.y+this.speed;
}
if(this.node.y>=600){
game.onBulletKilled(this.node);
}
},站长微信:xiaomao0055
站长QQ:14496453