Sawyer Posted May 17, 2016 Share Posted May 17, 2016 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() { this.state.start("Menu"); }); 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); and this.game.input.keyboard.reset(true); 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: Is there a cleaner way to do this? Would having an empty callback like this impact performance in any way? brentstrandy 1 Link to comment Share on other sites More sharing options...
brentstrandy Posted May 18, 2016 Share Posted May 18, 2016 I have the same question. I'm adding a comment so I know when someone responds... Link to comment Share on other sites More sharing options...
Skeptron Posted May 18, 2016 Share Posted May 18, 2016 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. drhayes 1 Link to comment Share on other sites More sharing options...
sluice Posted October 6, 2016 Share Posted October 6, 2016 A bit late to the party, but... this.game.input.keyboard.stop(); Will stop the keyboards events from being fired. Link to comment Share on other sites More sharing options...
lewster32 Posted October 7, 2016 Share Posted October 7, 2016 The addCallbacks method is just a helper for setting onDownCallback, onUpCallback and onPressCallback. See the documentation for more details: http://phaser.io/docs/2.6.2/Phaser.Keyboard.html Link to comment Share on other sites More sharing options...
samme Posted October 7, 2016 Share Posted October 7, 2016 It looks like you should just do var keyboard = this.game.input.keyboard; keyboard.onDownCallback = keyboard.onUpCallback = keyboard.onPressCallback = null; lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts