ryanisaacg / quicksilver

A simple framework for 2D games on desktop and web
https://ryanisaacg.github.io/quicksilver
Other
785 stars 77 forks source link

Keyboard not always working when on itch.io #565

Closed lenscas closed 4 years ago

lenscas commented 4 years ago

Describe the bug There have been multiple times now that input wasn't working in a game I made that is now hosted on itch.io. It uses a stand-alone page, as I saw this bug happen originally on an embedded page and hoped using a stand alone page would fix it. However, one of my users reported the same bug.

It doesn't seem to happen often, and with 0.4 changing a lot of things I'm planning to wait until I'm able to port that game to 0.4 to see if this issue still happens (I think the only thing preventing that from happening right now is text rendering).

Feel free to close this issue if you rather wait until I'm able to verify its existence in 0.4, think it is just noise right now, etc, etc.

To Reproduce Sadly it doesn't happen often enough to know how to even begin at figuring out how to reproduce it.

Environment and versions (please complete the following information):

ryanisaacg commented 4 years ago

Hm, without a repro I'm not sure what I can do here. I will say that it's possible the canvas / webpage lost focus, hence the keyboard event weren't being delivered?

lenscas commented 4 years ago

clicking on the canvas didn't work, only refreshing. I can give you a repo but the code is horrible. Feedback of the game is good so far so I may clean it up soon(ish)

If someone cares enough the code is here https://github.com/lenscas/glitch_dungeon itch.io page https://lenscas.itch.io/glitch-dungeon

I use this function to check if someone pressed enter, and call it every update

pub fn check_multiple_pressed(board: &Keyboard, to_check: &[Key]) -> bool {
    to_check
        .iter()
        .map(|v| board[*v])
        .map(|v| v == ButtonState::Pressed)
        .any(|v| v)
}

the function is in https://github.com/lenscas/glitch_dungeon/blob/master/src/player.rs The check is in https://github.com/lenscas/glitch_dungeon/blob/master/src/main.rs (line 311)

Anyway, right now it is not that big of a deal, as the work around is easy enough (just refresh) and it also doesn't happen often. Just focus on 0.4 and when I get time to port that game to it I'll see if I can reproduce it.

lenscas commented 4 years ago

I did some quick testing a bit ago with the game. It does seem to be related with focus, which is odd because in order to get to the game you need to click on a button inside the browser.

lenscas commented 4 years ago

I forgot to update this issue.

The same behavior was found with 0.4 when the game was embedded in the page. An additional click was needed for it to get any actual input.

ryanisaacg commented 4 years ago

Clicking on the canvas once is necessary for it to gain browser focus, which is necessary for keyboard input to be reported. That is expected behavior; is that what you're seeing?

lenscas commented 4 years ago

on itch.io there are 2 ways to make a browsergame playable.

The first is embedded. In that case, the game will be directly embedded in the itch page and the only thing from stopping it being directly being played as a "play" button provided by itch.

In that case, I expect that clicking this button is enough to play the game What happens: After clicking play, I need to click on the game again for it to get focus.

There is also the "click to launch in full screen" option. This also gives the itch page a "play" button however, instead of loading the game into the current page you are instead brought to another one that just contains the game.

Here I also need to click on the game again to gain focus, however a page refresh can also do the trick. (At least it did in quicksilver 0.3. Not sure if that is still the case)

Other engines don't seem to have this missing focus problem. If that was the case I would have guessed it is a problem purely on the side of itch.io.

ryanisaacg commented 4 years ago

Hm, I wonder if requesting focus to the canvas when the program starts is the way to go.

For clarification, in the itch web interface, is the game running before you click the 'play' button? Or does it only start after you click 'play'?

lenscas commented 4 years ago

To my knowledge the game only starts after clicking play. It uses an iframe which I guess only gets its contents added after you clicked play

ryanisaacg commented 4 years ago

Okay, you should be able to cargo update and get the new version. Let me know if that doesn't fix it!