Sign in to follow this  
Faizy

Signals in Phaser

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!.

Share this post


Link to post
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();
  }
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.