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

scenes consistently swallowing keyboard events after switching back and forth #3126

Closed
andybarron opened this issue Jul 16, 2024 · 4 comments · Fixed by #3127
Closed

scenes consistently swallowing keyboard events after switching back and forth #3126

andybarron opened this issue Jul 16, 2024 · 4 comments · Fixed by #3127
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior

Comments

@andybarron
Copy link

NB: Thanks so much for this incredible project! I'm happy to take a stab at fixing this if anyone can point me in the right direction :)

Steps to Reproduce

Create two scenes that toggle back and forth with two different key presses:

import * as ex from "excalibur";

const a = new ex.Scene();
a.on("initialize", () => {
  a.input.keyboard.on("press", (e) => {
    if (e.key === ex.Keys.Key1) {
      a.engine.goToScene("b");
    }
  });
});

const b = new ex.Scene();
b.backgroundColor = ex.Color.DarkGray;
b.on("initialize", () => {
  b.input.keyboard.on("press", (e) => {
    if (e.key === ex.Keys.Key2) {
      b.engine.goToScene("a");
    }
  });
});

const game = new ex.Engine({
  scenes: { a, b },
});

game.goToScene("a");
game.start();

The issue does not appear if you target the same key code in both scenes.

Expected Result

  • Pressing "1" always transitions scene A to scene B
  • Pressing "2" always transitions scene B to scene A

Actual Result

  • Pressing "1" always transitions scene A to scene B ✅
  • Pressing "2" always transitions scene B to scene A ❌
    • It works once. On subsequent attempts, you have to press "2" twice.
    • It seems like the key gets "stuck" in the down state due to the scene changes, and the first press "releases" it.
    • Not sure why it doesn't happen to the initial scene.

Environment

  • browsers and versions: Firefox (128.0, 64-bit), Chrome (126.0.6478.127, arm64)
  • operating system: macOS 14.5 (Sonoma) - MacBook Air (M1, 2020)
  • Excalibur versions: 0.29.0, 0.29.3, 0.30.0-alpha.1105
    • Older versions (<=28.0) don't have the scene-specific input API, so they seem to be unaffected

Current Workaround

Haven't found one 😞

@eonarheim eonarheim added the bug This issue describes undesirable, incorrect, or unexpected behavior label Jul 16, 2024
@eonarheim
Copy link
Member

@andybarron Thanks for the issue, and the kind words!

Definitely feels like a bug to me, let me dig around quick with your example to see if anything jumps out.

@eonarheim
Copy link
Member

@andybarron I think your intuition is spot on, I have some local tests that look like this is the problem. I should have a fix sometime today

It seems like the key gets "stuck" in the down state due to the scene changes, and the first press "releases" it.

@eonarheim
Copy link
Member

@andybarron This is merged into main, should be deployed to the alpha npm package soon.

I have a few more bugs to fix before I cut the next v0.29.4, probably end of July?

@andybarron
Copy link
Author

@eonarheim just installed the latest alpha and it works like a charm! thanks 😄 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants