InsaneHero Posted October 11, 2013 Share Posted October 11, 2013 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 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 More sharing options...
rich Posted October 11, 2013 Share Posted October 11, 2013 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 More sharing options...
InsaneHero Posted October 11, 2013 Author Share Posted October 11, 2013 Sweet thanks! I don't know how I missed the remove function, I'm sure I searched for that.BTW: my current project is a Phaser version of Zombaby Bouncer, it's coming along very nicely too Link to comment Share on other sites More sharing options...
Recommended Posts