请教一个问题,节点无法从界面移除怎么办

描述:1.子弹是prefab 采用的是对象池,在子弹碰撞后put回对象池,但是界面的子弹未消失。
2.通过 if(cc.isValid(this.node)){
this.node.destroy()
}
判断的结果全是true,结果也是界面的子弹还是存在! 但是这两种方法并不是所有生成的子弹都不会消失,偶尔会有几个留在屏幕上。
碰撞:onEndContact及判断otherCollider.tag

应该是你逻辑问题,是不是循环没有遍历到全部子弹

你确定碰撞到所有的子弹了吗?建议回去先好好检查自己的代码

我只用了一个预制体! 不是全部都不能消失,偶尔有几个不能消失!

录像12.zip (65.8 KB)

用的是while还是for,要是for的话,改用while,然后每次都判断父节点下的第一个子节点

onLoad() {
cc.director.getPhysicsManager().enabled = true;
this.node.getComponent(cc.PhysicsChainCollider).tag = 0;
}

onEndContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider) {
    if (otherCollider.tag == 2) {
        this.node.destroy();
       // console.log(this.is_ac++)
    }
}

}

我现在测试用的这个,和对象池也是一样的无法消除

createEnemy() {
let getfoe = cc.find(‘Canvas’).getComponent(‘game’);
let foes_x = getfoe.foe.getPosition().x;
let foes_y = getfoe.foe.getPosition().y;
let enemy = null;

enemy = cc.instantiate(getfoe.foes_arr[0]);
enemy.parent = cc.find('Canvas');
enemy.setPosition(foes_x, foes_y + 50)
enemy.runAction(cc.moveBy(0.4, 1140, 0))

}

现在我只用了一个prefab 然后直接生成的 ! 麻烦看下下方代码帮我分析分析

你的this.node指的是?

onLoad() {
cc.director.getPhysicsManager().enabled = true;
this.node.getComponent(cc.PhysicsChainCollider).tag = 0;
}

onEndContact(contact: cc.PhysicsContact, selfCollider: cc.PhysicsCollider, otherCollider: cc.PhysicsCollider) {
if (otherCollider.tag == 2) {
this.node.destroy();
// console.log(this.is_ac++)
}
}

这个是挂在子弹上的脚本! 生成的脚本是挂在canvas上用计时器生成子弹! 然后子弹碰撞到一个障碍物tag=2的就destroy

我说下我的想法 不知道对不对 直接用 removefromparent 不就行了 从父节点移除掉这个节点 然后在放进对象池