Jump to content

Signals in Phaser


Faizy
 Share

Recommended Posts

Hey,

 

I need some kind of a listener, which looks 24/7 if a specific event happens and triggers a function/callback. A basic example: if a player reaches position X, a function should be triggered, which adds a scorepoint. Is it possible to define a specific event, which get´s checked 24/7 if happening, and if yes, a specific function will get fired? I cant figure out where I can set up the condition, even after reading this

 

Thanks!.

Link to comment
Share on other sites

Yes, you still have to do the check yourself. It would look something like

function create() {
  this.onPlayerReachedGoal = new Phaser.Signal();
}

function update() {
  if player.position.distance(goal) < 1 {
    this.onPlayerReachedGoal.dispatch();
  }
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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