Skip to content

Setting enabled = false on a key while it is down does not reset the isDown state #1190

@lazd

Description

@lazd

If a key is disabled while it is down, the isDown property remains true. I would expect isDown to be set to false when the key is disabled so game code doesn't assume the key is pressed.

Test case

Run the following code in the console of any Phaser 2.x game and press X on your keyboard.

var xKey = game.input.keyboard.addKey(Phaser.Keyboard.X);
setTimeout(function() {  // The timeout is here to give you time to press X
  xKey.enabled = false;
  console.assert(xKey.isDown === false, 'The key should not be down when disabled');
}, 3000);

In 3 seconds, you should get an AssertionError:

Assertion failed: The key should not be down when disabled 

Workaround

Call xKey.reset() when disabling the key.

var xKey = game.input.keyboard.addKey(Phaser.Keyboard.X);
setTimeout(function() {  // The timeout is here to give you time to press X
  xKey.enabled = false;
  xKey.reset();
  console.assert(xKey.isDown === false, 'The key should not be down when disabled');
}, 3000);

Details

  • Phaser 2.1.0
  • Mac OS X 10.9.2
  • Chrome 37.0.2062.94

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions