Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keys lose track of state when scene paused #3822

Closed
DannyT opened this issue Jul 8, 2018 · 3 comments
Closed

Keys lose track of state when scene paused #3822

DannyT opened this issue Jul 8, 2018 · 3 comments

Comments

@DannyT
Copy link
Contributor

DannyT commented Jul 8, 2018

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.

@zzox
Copy link

zzox commented Nov 28, 2018

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.

@jackfreak
Copy link

jackfreak commented Mar 15, 2019

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.

@photonstorm
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants