phaser icon indicating copy to clipboard operation
phaser copied to clipboard

Keys lose track of state when scene paused

Open DannyT opened this issue 8 years ago • 3 comments

If you're holding a key (e.g. holding down after a createCursorKeys() call) and the scene gets paused, that key will remain in its isDown state even when the key is depressed whilst paused.

Here's an example against 3.10.1: https://codepen.io/DannyT/pen/LrwgVe

Hold down key click to pause and switch scene depress down and press space to switch back isDown is maintained and lose your hotdog forever :(


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

DannyT avatar Jul 08 '18 13:07 DannyT

I have been having this same problem but on changing scenes. A temporary solution for me has been having a clearKeys() function that I call whenever I change scenes:

  clearKeys () {
    this.input.keyboard.removeKey(Phaser.Input.Keyboard.KeyCodes.ENTER)
    this.input.keyboard.removeKey(Phaser.Input.Keyboard.KeyCodes.UP)
    this.input.keyboard.removeKey(Phaser.Input.Keyboard.KeyCodes.DOWN)
  }

and that fixes the problem, the keys just have to be re-added every time.

zzox avatar Nov 28 '18 14:11 zzox

I was banging my head around this too.

For anyone having this issue, I found https://photonstorm.github.io/phaser3-docs/Phaser.Input.Keyboard.KeyboardPlugin.html#resetKeys__anchor

Listening for the Phaser.Scenes.Events.PAUSE event in the scene, and then calling resetKeys() in the event handler seems to do the trick.

jackfreak avatar Mar 15 '19 20:03 jackfreak

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

photonstorm avatar Apr 24 '19 10:04 photonstorm