Jump to content

phaser-group-signals: onChildAdded, onChildRemoved, onChildKilled, onChildRevived


samme
 Share

Recommended Posts

GitHub / NPM

group.onChildAdded.add(function (child, parent){
    /* `child` was added to `parent` */
});

group.onChildRemoved.add(function (child, prevParent){
    /* `child` was removed from `prevParent` */
});

group.onChildKilled.add(function (child, parent){
    /* `child` was killed */
});

group.onChildRevived.add(function (child, parent){
    /* `child` was revived */
});

 

Link to comment
Share on other sites

Hi tips, definitely, you could; I suppose it helps with separation of concerns and could simplify complex relationships. I wanted to find a way some interested entity could monitor a group without ever having to visit its children.

I think the biggest advantage is you can respond to changes in children created after you've attached to the signal, forever. It also reduces signal volume for very large groups.

Slightly interesting: `onChildAdded` is triggered by auto-expanding Bullet groups and createIfNull: true. And you can monitor every game object by binding just 4 signals on `game.world`.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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