尝试修改代码运用新的NodePool但是遇到了这个问题。
报错
Uncaught TypeError: obj.removeFromParent is not a function
代码
const PipeGroup = require(‘PipeGroup’);
cc.Class({
extends: cc.Component,
properties: {
pipePrefab: cc.Prefab,
pipeLayer: cc.Node,
initPipeX: 0,
spawnInterval: 0
},
onLoad () {
Global.pipeManager = this;
this.pipeGroupPool = new cc.NodePool();
},
startSpawn () {
this.spawnPipe();
this.schedule(this.spawnPipe, this.spawnInterval); // spawnInterval in seconds
},
spawnPipe() {
let pipeGroup = null;
if (this.pipeGroupPool.size() > 0) {
pipeGroup = this.pipeGroupPool.get();
} else {
pipeGroup = cc.instantiate(this.pipePrefab).getComponent(PipeGroup);
}
this.pipeLayer.addChild(pipeGroup.node);
pipeGroup.node.active = true;
pipeGroup.node.x = this.initPipeX;
},
destroyPipe(pipe) {
// pipe.node.removeFromParent();
console.log(typeof(pipe), pipe);
pipe.node.active = false;
this.pipeGroupPool.put(pipe);
},
stop() {
this.unschedule(this.spawnPipe);
}
});

