我的项目中有一个Prefab,它有一个脚本,其中有一个函数是这样:
explode() {
let fx = this.spawnBoomFX()
this.node.parent.addChild(fx.node)
fx.node.setPosition(this.node.position)
fx.play()
// 擦除当前节点并生成新节点
this.node.removeFromParent()
cc.pool.putInPool(this)
this.frame.spriteFrame = this.arrow[0]
},
它在执行:
if (this.missile.y < -110) {
this.velocity = null
this.isUp = true
this.missile.getComponent(Missile).explode()//这一句
}
的时候没有问题。
但是一放到:
onCollisionEnter(other, self) {
this.explode()
},
就会提示错误:
Uncaught TypeError: Cannot read property ‘addChild’ of null
this.node.parent.addChild(fx.node)
这个节点的父节点为空
请问这个问题怎么解决?


