Jump to content

Childs Ticker Listener


Gerente
 Share

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.

 

Link to comment
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!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...