Jump to content

disable event listeners


InsaneHero
 Share

Recommended Posts

This is probably a dumb question, but how do I disable an event listener when I no longer want it?

 

I'm using game.input.onDown.add(game_create, this); to start my game when the titles are clicked, but in function game_create I obviously want to switch off that event.

 

I've looked in all the examples, tried searching the phaser source, and done a forum search but now I'm stumped  :unsure:

 

I also tried (randomly), game.input.reset() game.input.onDown.kill() and game.input.onDown = null.  I couldn't find an onDown.remove function which seemed like a good idea at the time.

 

I could just point it at an empty function, but that's tacky and the use of 'onDown.add' makes me wonder if that will just add another listener rather than replace the existing one.

 

Link to comment
Share on other sites

game.input.onDown.remove(game_create, this);

You have to give it the same function / scope you used when adding it in order for remove to work.

 

You can also do:

game.input.onDown.removeAll();

and there are other useful functions too like: getNumListeners(), addOnce(), halt(), dispatch(), forget() and dispose().

 

For details look at src/core/Signal.js

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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