Jump to content

Listen to events from deep descendant


Lawrence
 Share

Recommended Posts

For example if I keep the display objects in this structure:

A contains B contains C contains D

I have a controller X that has a reference of A. Then X wants to react to signals dispatched from D, but I don't want X to directly interact with D. And I want each layer to only deal with their immediate child objects. It seems the only pattern I can do is to have the events propagate one level each time. e.g. in different places I will have to do:

d.events.onFooD = new Phaser.Signal();

c.events.onFooC = d.events.onFooD;

b.events.onFooB = c.events.onFooC;

a.events.onFooA = b.events.onFooB;

Then in X:

a.events.onFooA.add(function(){

});

Is that a correct approach?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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