Jump to content

Enable/disable keyboard input on specific keys?


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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...