pixijs / spine

Pixi.js plugin that enables Spine support.
Other
564 stars 217 forks source link

Animation listener not called when spine is not visible #258

Open jeremygillespiecloutier opened 6 years ago

jeremygillespiecloutier commented 6 years ago

When I start a looping spine animation and set the spine invisible before it completes a cycle of the animation, the complete event does not get triggered. The animation only continues to run after I set the spine visible, even if I wait much longer than the duration of the animation before doing so.

var spine=new PIXI.spine.Spine(spineData);
spine.state.addListener(
{
    complete:function()
    {
        console.log("Completed");
    }
});
spine.x=300;
spine.y=300;
container.addChild(spine);
spine.state.setAnimation(0, "explosion", true);
spine.visible=false;  

In the previous block, "Completed" never gets printed. Is there a way to circumvent this? I know using alpha=0 instead of visible=false works, but I need to hide spines for performance considerations and setting the visibility to false is needed to this. However, I don't want my animation logic which relies on listener callbacks to be affected. Can spines be invisible but still be animating even though they are not being rendered?

ivanpopelyshev commented 6 years ago

set "renderable=false" instead. visible is too much, alpha=0 is good enough (we dont render such elements), but correct way is turn off renderable.

jeremygillespiecloutier commented 6 years ago

Thanks, I didn't know about this property! Now it works as I want it to.

ivanpopelyshev commented 6 years ago

I suggest you study this class: https://github.com/pixijs/pixi.js/blob/dev/src/core/display/Container.js#L394 and maybe DisplayObject too. There are many tricks inside, dont think that its like a blackbox, its readable enough and i know that big project just change those classes to suit their needs.