Outfire

Members
  • Content count

    6
  • Joined

  • Last visited

About Outfire

  • Rank
    Newbie
  • Birthday February 7

Profile Information

  • Gender
    Male
  1. RemoveListener for Spine animations

    I considered on how to implement function to remove listeners, and here is the result. The following code can be used to remove function from particular listener. PIXI.spine.core.AnimationState.prototype.removeListenersByName = function (findListener) { this.listeners.forEach( listener => { for(let currentListenerName in listener) { for(let findListenerName in findListener) { if (currentListenerName === findListenerName && listener[currentListenerName].name === findListener[findListenerName]) { if(Object.keys(listener).length === 1) { this.removeListener(listener); } else { delete listener[currentListenerName] } } } } }) } spine.addListener({ complete: foo, end: bar }) removeListenersByName({ complete: 'foo' }) removeListenersByName({ complete: 'foo', end: 'bar' }) But this solution has one problem. spine.addListener({ complete: foo.bind(this)}) Then listeners[0].complete.name will be 'bound foo', not 'foo'.This problem can be solved in the following way. PIXI.spine.core.AnimationState.prototype.isBounded = function (listenerName, findName) { let splited = listenerName.split(' '); if (splited.length === 1) { return false; } return splited[0] === 'bound' && splited[1] === findName } PIXI.spine.core.AnimationState.prototype.removeListenersByName = function (findListener) { this.listeners.forEach( listener => { for(let currentListenerName in listener) { for(let findListenerName in findListener) { if (currentListenerName === findListenerName) { let currentName = listener[currentListenerName].name; let findName = findListener[findListenerName]; if (this.isBounded(currentName, findName)) { findName = 'bound ' + findName; } if (currentName === findName) { if(Object.keys(listener).length === 1) { this.removeListener(listener); } else { delete listener[currentListenerName] } } } } } }) }; Some other issue can appear. spine.addListener({complete: () => console.log('something') }); Here listeners[0].complete.name will be 'complete', as the name of the listener, to which function it was bound. But it's just information. To remove all functions from particular listener. PIXI.spine.core.AnimationState.prototype.clearListenersByName = function (listenerName) { this.listeners.forEach( listener => { for(let key in listener) { if (key === listenerName) { if(Object.keys(listener).length === 1) { this.removeListener(listener); } else { delete listener[key] } } } }) } spine.addListener({ complete: foo, end: bar }) spine.addListener({ complete: foo}) clearListenersByName('complete') That is the result of my small expierence in js.
  2. RemoveListener for Spine animations

    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?
  3. RemoveListener for Spine animations

    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 .
  4. 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?
  5. One atlas many json for spine

    Thanks! All is fine.
  6. One atlas many json for spine

    I want to use one atlas for many spine animations in my game. I found the way how to do it with loader. I am loaded atlas with game loader (name other.atlas) and got in game.loader.resources.other. Then i am trying to load json file of my animation from console. otherLoader = new PIXI.loaders.Loader() spineLoaderOptions = { metadata: { spineAtlas: 'game.loader.resources.other' } }; otherLoader.add('someJson', 'static/img/content/fullHD/machine/elements/testJ.json', spineLoaderOptions) .load() But it will not work. Loader still wants to load atlas with name of my json. GET http://localhost:3004/static/img/content/fullHD/machine/elements/testJ.atlas 404 (Not Found) I think it is because of atlas parser . I need varibale "pages" in my metadataAtlas, but there is no pages. How atlas data looks like in console. I am doing something wrong and i dont know what.