Jump to content

Phaser Signal usage & examples


pixelhijack
 Share

Recommended Posts

Hey guys, 

can you point me at any example usage of Phaser Signals which is a bit more in-depth than a 2-liner? Surprised me how few descriptions i found compared how powerful / important feature it is in Phaser, and how many question admittedly coming on this topic. I read the other link i found 

What i would be curious: 1. example how to implement publish-subscribe / observers with Signals from player's hero to enemy types & vice-versa, or 2. examples on a general architecture / best practices for broader usage on custom events in a Phaser game, any case study etc. I'm sure i'll come out my own solutions soon, but would really curious how you are using, as relying fully on events are becoming widespread in the wider webdev world, i.e. Flux, Redux

Thanks!

Link to comment
Share on other sites

I'm not sure there is a huge need to overly document the signals mechanism with loads of tutorials etc, as you've pointed out, it is simply a quick pub/sub library so all the theory that applies to pub/sub applies here. Redux works differently (it is not pub/sub), but, inherently, JS (and therefore the web) works via pub/sub, it's just that often the events that are emitted come from outside JS (i.e. you addEventListener, user clicks a button which emits the event).

The Phaser Signals lib looks like it has some additions to a 'clean' pub/sub, namely the memorising and releasing, but, despite a few naming differences, it is essentially the pub/sub you know and love on the web. As it should be, no magic involved.

If you're unclear on how pub/sub works there is a lot of info out there, I'm not sure that there are many languages out there that do not allow/implement pub/sub, whether you agree with it or not its been a staple of programming for a very long time.

If you really want to get into the meat of it then modelling application state can become a very technical discussion, and can evoke many different responses on what is/isnt nice/good/bad.

Do you want an example of how pub/sub could help one entity communicate with another? Or do you want to know if that sort of architecture is even feasible? Or a good idea?

Link to comment
Share on other sites

Thanks guys! Mattstyles, you are right, it is really just another pub/sub. What i was confused is just the naming differences (especially the .add() subscribe method), but as i dig deeper for now all clear. I used Tom Atom your tutorial and found an other one too (http://www.emanueleferonato.com/2016/03/16/understanding-signal-dispatch-with-phaser/), then came up with my own decorators with a slightly different signatures, works like a charm. Later maybe i will write my lessons learnt on Phaser Signals :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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