Jump to content

Turn off keyboard events after game over


koko
 Share

Recommended Posts

How do I turn the keyboard events on and off propoerly when switching between states?

Currently, in create method of my game state I setup keyboard events like this:

this.game.input.keyboard.addKey(Phaser.Keyboard.P).onDown.add(function () {
	game.paused = !game.paused;
});

this.game.input.keyboard.addKey(Phaser.Keyboard.M).onDown.add(function () {
	game.sound.mute = !game.sound.mute;
});

How do I turn it off in shutdown() method without removing each event separately? Of course, I'd like to turn them back on when returning to the game state. 

I tried:
 

this.game.input.keyboard.reset(); /// does not stop listeners at all

this.game.input.keyboard.stops(); /// stops listeners but does not restarts them

this.game.input.keyboard.destroy(); /// stops listeners but does not restarts them

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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