koko Posted January 20, 2016 Share Posted January 20, 2016 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 More sharing options...
Recommended Posts