Gerente Posted February 18, 2018 Share Posted February 18, 2018 Hello, I have a PIXI app with many child (in a tree structure). I need to update only child that contains the method "update". There is any logic inside PIXI for this or I would need to add each of those object in the shared.ticker? I did this, but there could be a better way that could allow me to remove the ticker listener if I need to. THIS IS NOT FOR SPRITE ANIMATIONS, it's mostly to change objects position https://jsfiddle.net/32ce1rcw/2/ Thanks. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted February 18, 2018 Share Posted February 18, 2018 Pixi doesn't have special logic regarding adding/removing listeners for ticker. I have PR for PIXI to improve the situation: https://github.com/pixijs/pixi.js/pull/4586 For now you have to make your own system that tracks instanced that has to be updated. Quote Link to comment Share on other sites More sharing options...
Gerente Posted February 18, 2018 Author Share Posted February 18, 2018 Ivan!!. Im not liking to do so many hack but I don't see other way to do it without waiting for new releases. Please give me you opinion on this, would this fail in any scenario? https://jsfiddle.net/32ce1rcw/15/ PIXI.Container.prototype.onChildrenChange = function(childIndex){ let child = this.children[childIndex] console.log(childIndex, this.children) if(this.children.length > 0 && child.hasCustomEvents != true){ child.hasCustomEvents = true //Define here any custom event let customEvents = ['update','render'] for(let i=0;i<customEvents.length;i++){ let eventName = customEvents[i] if(typeof child[eventName] == 'function'){ child.on('added',function(parent){ console.log('LISTENER ADDED',eventName, child[eventName]) PIXI.ticker.shared.add(child[eventName],child) }) child.on('removed',function(parent){ console.log('LISTENER REMOVED',eventName, child[eventName]) PIXI.ticker.shared.remove(child[eventName],child) }) } } } } Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.