Javascript 删除Pixi应用程序中子对象的所有子对象

Javascript 删除Pixi应用程序中子对象的所有子对象,javascript,pixi.js,Javascript,Pixi.js,我正在尝试删除pixi应用程序中childen的所有子项,但是一些精灵项目仍然保留,并且在经过一个二人游戏后失败。。以下内容位于名为appEntry的类中 create(){ this.renderer = new Renderer({ resolution: window.devicePixelRatio }); this.renderer.backgroundColor = 0x260244; this.app = new Container(); thi

我正在尝试删除pixi应用程序中childen的所有子项,但是一些精灵项目仍然保留,并且在经过一个二人游戏后失败。。以下内容位于名为appEntry的类中

create(){
    this.renderer = new Renderer({ resolution: window.devicePixelRatio });
    this.renderer.backgroundColor = 0x260244;

    this.app = new Container(); 
    this.loader = new Loader(); 

    console.log('PIXI APP INIT!');

    document.getElementById('pixi-render').appendChild(this.renderer.view);
    console.log('RENDERER APPENDED:', this.renderer);
    console.log('PIXI APP APPENDED:', this.app);

    AnimationStore.subscribe(() => {
       this.renderer.render(this.app);
    });

    Store.subscribe(() => {
       const { color, coloron } = Store.getState().App;
    });

    const main = new Main();
    this.app.removeChild(this.loader);
    this.app.addChild(main); 
    this.renderer.start();
}

destroy(){
    this.app.destroy(true);
    this.app = null;

    this.renderer.view.destroy( true );
    this.renderer.view = null;

    while(this.app.children[0]) { 
    this.app.removeChild(this.app.children[0]); }

    this.renderer.destroy( true );
    this.renderer = null;
    console.log('PIXI APP APPENDED:', this.app);
}

似乎destroy方法的设计不正确,并且不清楚为什么在执行时浏览器中没有错误:this.app变量在(this.app.children[0])删除所有子变量之前被清空

首先,我建议下一步改变方法:

destroy(){
    while(this.app.children[0]) { 
        this.app.removeChild(this.app.children[0]);
    }

    this.app.destroy(true);
    this.app = null;

    this.renderer.view.destroy( true );
    this.renderer.view = null;

    this.renderer.destroy( true );
    this.renderer = null;
    console.log('PIXI APP APPENDED:', this.app);
}
此外,请确保您的错误与tween仍然处于活动状态,但其tween目标已经无效/删除/销毁这一事实无关。如果是这样的话,那么除了移除可视对象之外,您还需要停止/销毁所有tweens