Jump to content

Enable/disable keyboard input on specific keys?


spinnerbox
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

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