-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Closed
Labels
Description
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