spinnerbox Posted April 27, 2017 Share Posted April 27, 2017 In my main scene I add keyboard event listeners to specific keys in the init() state. Also some of those keys need to be disabled at specific time and re-enabled at specific time. How can I disable/enable input on specific keyboard buttons at runtime? Link to comment Share on other sites More sharing options...
spinnerbox Posted April 27, 2017 Author Share Posted April 27, 2017 Not sure if there is cleaner way to enable/disable keyboard input like for buttons, button.inputEnabled = false/true, but I created my own functions and used add/remove functions of the Phaser.Signal class: initKeyboard: function() { aKey = gameObject.input.keyboard.addKey(phaser.Keyboard.A); aKey.onDown.add(this.guess, answer1Btn); leftKey = gameObject.input.keyboard.addKey(phaser.Keyboard.LEFT); leftKey.onDown.add(this.guess, answer1Btn); uKey = gameObject.input.keyboard.addKey(phaser.Keyboard.U); uKey.onDown.add(this.updateFields, this); pKey = gameObject.input.keyboard.addKey(phaser.Keyboard.P); pKey.onDown.add(this.pauseUnpauseGame, this); oKey = gameObject.input.keyboard.addKey(phaser.Keyboard.O); oKey.onDown.add(this.saveData, this); spaceKey = gameObject.input.keyboard.addKey(phaser.Keyboard.SPACEBAR); spaceKey.onDown.add(this.submit, this); enterKey = gameObject.input.keyboard.addKey(phaser.Keyboard.ENTER); enterKey.onDown.add(this.submit, this); iKey = gameObject.input.keyboard.addKey(phaser.Keyboard.I); iKey.onDown.add(this.showResetWindow, this); }, disableKeys: function() { aKey.onDown.remove(this.guess, answer1Btn); leftKey.onDown.remove(this.guess, answer1Btn); spaceKey.onDown.remove(this.submit, this); enterKey.onDown.remove(this.submit, this); uKey.onDown.remove(this.updateFields, this); }, enableKeys: function() { aKey.onDown.add(this.guess, answer1Btn); leftKey.onDown.add(this.guess, answer1Btn); spaceKey.onDown.add(this.submit, this); enterKey.onDown.add(this.submit, this); uKey.onDown.add(this.updateFields, this); }, Link to comment Share on other sites More sharing options...
samme Posted April 27, 2017 Share Posted April 27, 2017 See Phaser.Key#enabled spinnerbox 1 Link to comment Share on other sites More sharing options...
Recommended Posts