遇到一个奇怪的问题

this.nodePool = new cc.NodePool();
clearNode(){
while(this.node.childrenCount){
this.pool.put(this.node.children.shift());//使用该方法存入缓存池后,再次取出使用看不到
this.pool.put(this.node.children[0]);//使用该方法正常
}
console.log(this.node.childrenCount);
}

addNode(pos){
let node;
if (this.nodePool .size() > 0) {
node = this.pool.get();
} else {
node = new cc.Node();
node.addComponent(cc.Sprite);
helper.loadResImg(node,“public/paopao”);

    }
    node.parent = this.node;
    node.position = pos;

}

children 应该是 只读的,不能直接用 shift 操作。

但是从缓存池里能取到该节点。只是再次添加到场景上没有成功。场景子对象依然为0

你通过非常规的方式移除了子对象,引用关系可能出了问题。不用shift这种会修改数组的操作就行了。

我之前也用过children.splice()是可以的删除child的,升级2.2.0之后不生效了