Sign in to follow this  
Gerente

Childs Ticker Listener

Recommended Posts

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.

 

Share this post


Link to post
Share on other sites

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!

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.