Sign in to follow this  
Outfire

RemoveListener for Spine animations

Recommended Posts

RemoveListener is works, but only in one way:

let spine // our spine animation
let log = () => console.log('nonsense');
let listener = {complete: log};

spine.state.addListener(listener);

And removes it like

spine.state.removeListener(listener);

It does not work if i do it like this:

let spine //our spine animation
let log = () => console.log('nonsense');

spine.state.addListener({complete: log});
// trying to remove
spine.state.addListener(log);
// or just like this
spine.state.addListener({complete: log});

Works fine if add and remove only the same object, but its long way.
Is there another way to do this?

 

image.png

Share this post


Link to post
Share on other sites

I like the idea.

This is the part in pixi-spine: https://github.com/pixijs/pixi-spine/blob/master/src/core/AnimationState.ts#L561

This is upstream, spine-ts: https://github.com/EsotericSoftware/spine-runtimes/blob/3.6/spine-ts/core/src/AnimationState.ts#L561

You can hack pixi-spine:

PIXI.spine.core.AnimationState.prototype.removeListener = function (...) { }

Please make PR or at least give me the code with the behaviour you want. I'm all hands for enhancing pixi-spine, we already have some things that distinguish us from spine-ts.

Share this post


Link to post
Share on other sites

Need some time to think about it.


I think about "spine.removeListener({complete: log})"
But we can add "log" twice or more in one "complete", and then our removeListener must remove all "log"s in "complete" or just the last one.


Maybe it is possible to do like in DOM addEventListener, when you add new listener on the same event with the same listener name it removes old one and push new one instead of it .

Share this post


Link to post
Share on other sites

Yes, it is my problem if I  forget that I already have listener with the same name.

I think variant - "spine.removeListener({complete: 'log'})" (event name and listener name) - is the best way and pretty obvious one.

And "spine.removeListener({complete: ['log', 'update'], start: 'playSound'})" to remove multiple events. 

Perhaps is it possible to upgrade  clearListeners function , so it takes event name as an argument and as result removes all listeners subscribed to this particular event?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.