Jump to content

Remove keyboard callback


Recommended Posts

I have an opening screen to my game where the use can press any key to start.

I implemented this using:

  this.game.input.keyboard.addCallbacks(this, function() {

My problem is that this callback persists over into other states, so if I press any key it always take me back to my Menu state.

I've looked at the Documentation and tried both:

  this.game.input.keyboard.addCallbacks(this, null, null, null);



Neither of which did the trick.

I then simply replaced the callback with:

this.game.input.keyboard.addCallbacks(this, function() {});

Which seems to have solved the problem.

2 questions here:

  1. Is there a cleaner way to do this?
  2. Would having an empty callback like this impact performance in any way?
Link to comment
Share on other sites

Maybe you could instead use this.game.input.keyboard.onDownCallback, and nullify it when done with it?

By the way, states have a shutdown() method called when the state is shutdown, so I guess it would be quite clean to nullify the onDownCallback method there.

Link to comment
Share on other sites

  • 4 months later...

  • Recently Browsing   0 members

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