文档地址:
Cocos Creator 3.8 手册 - 创建和销毁节点
start(){
// 5秒后销毁节点
setTimeout(function () {
this.target.destroy();
}.bind(this), 5000);
}
这样运行当销毁的时候,在update赋值会报错
我看了官方还有另外一个写法 this.node.destroy();
setTimeout(function () {
this.node.destroy();
}, 5000);
在update赋值还是会报错
我修改方法
setTimeout(function () {
this.node.destroy();
}.bind(this), 5000);
这样update的地方也不会报错了
这是为什么?
到底是 this.target.destroy()还是 this.node.destroy()才可以
为什么直接this.node.destroy()不可以,还需要bind(this)