You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
varxKey=game.input.keyboard.addKey(Phaser.Keyboard.X);setTimeout(function(){// The timeout is here to give you time to press XxKey.enabled=false;console.assert(xKey.isDown===false,'The key should not be down when disabled');},3000);
varxKey=game.input.keyboard.addKey(Phaser.Keyboard.X);setTimeout(function(){// The timeout is here to give you time to press XxKey.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
The text was updated successfully, but these errors were encountered:
lazd
changed the title
Setting enabled = false on a key while it is down does not reset the down state
Setting enabled = false on a key while it is down does not reset the isDown state
Sep 13, 2014
This is only possible if we swap enabled to be a getter/setter, which we could certainly do. Feels like hell of an edge case though, and easily avoided by calling Key.reset and then disabling it. Will flag it as a change request and see about adding.
Sounds like Key.reset() is a good enough workaround for now.
I ended up creating a moveDisabled variable and checking that in the game loop. There was less code (enabling/disabling two keys) and it was simple enough for my use case.
pnstickne
added a commit
to pnstickne/phaser
that referenced
this issue
Oct 29, 2014
- Added `enabled` getter; this resets the key (soft) and then disables they key
- Added `_enabled` property and updated internal usage
- Updated document for `reset`.
If a key is disabled while it is down, the
isDown
property remainstrue
. I would expectisDown
to be set tofalse
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.
In 3 seconds, you should get an AssertionError:
Workaround
Call
xKey.reset()
when disabling the key.Details
The text was updated successfully, but these errors were encountered: