LibGDX HTML Game Keyboard Controls Problem Solved



Yesterday, I have made a game using libGDX and published the html game to itch.io and gamejolt.com
Here is the game http://ravicake.itch.io/pong-simple

After that I've published the game, I try to play the game in the web browser. But I noticed that keyboard controls are not working. The game was working fine when testing.

I tried to view the game without iframe ( web games on gamejolt and itch.io are embedded in iframe ) by right clicking on the game frame and then -> show only this frame (in firefox). Voila! the keyboard controls are working fine again.

From that, it is clear that there are some problems which does not let keyboard controls to work in iframe.

I searched the internet but I could not find any solution. But after searching for some more time I got something.
I found a solution, not perfect but working. Here is it:

In libGDX's html game's index.html add the following line in the handleMouseDown() function

window.focus();

Now the keyboard controls are working as it should.

No comments:

Post a Comment