Not able to remove Spine on complete event of animation for PIXI version 7 and pixi-spine version 4.0.4
MayankDhankhar opened this issue · 1 comments
MayankDhankhar commented
I am not able to remove spine animation from PIXI.Container.
As soon as i removeChild it, it throws an error.
Please help.
Below is the code :
private testSpineAnimation(): void {
const resource = App.loader.resources.gfx['dice_Anim_1to5'];
const animation = new Spine(resource.spineData);
this.allSpineAnims = [];
this.allSpineAnims.push(animation);
// add the animation to the scene and render...
this.baseContainer.addChild(animation);
if (animation.state.hasAnimation('animation')) {
animation.scale.set(0.5);
animation.position.set(152, 552);
animation.state.addListener({
start: () => {
console.log("ANIMATION START");
},
end: () => {
console.log("ANIMATION END");
},
complete: (entry: ITrackEntry) => {
this.clearAndRemoveSpineAnimations();
}
});
// run forever, little boy!
animation.state.setAnimation(0, 'animation', false);
// dont run too fast
// animation.state.timeScale = 0.1;
// update yourself
animation.autoUpdate = true;
}
}
private clearAndRemoveSpineAnimations() : void {
for (let anim of this.allSpineAnims) {
anim.autoUpdate = false;
anim.state.clearTracks();
this.baseContainer.removeChild(anim);
}
}
MayankDhankhar commented
@ivanpopelyshev please help.