How to prevent scrolling windows with the game libgdx gwt

I export a gwt game from libgdx to Kongregate using the kongregate shell, which creates an iframe and puts the game into it. Looking around, I found out about tidbits on how to put window.focus () to let the game really pick up the keyboard, but when I use the arrow keys, it scrolls the actual browser window and also makes it very annoying.

Is there a way to ignore the browser when the iframe is in focus to avoid this?

thanks

+4
source share
2 answers

-, , issue.

, maxojr, script, :

function preventUseOfDefaultKeys(event) { // You can change the function name
    if(event.keyCode == 38) { // 38 would be the up arrow
        event.preventDefualt();
    }
}

body HTML ( iframe, , , ) <body> write <body onkeydown="preventUseOfDefaultKeys(event);" >. , .

, !

0

. , .

  • <body> index.html:

<input type="text" id="shazam" style="position: absolute; left: 50%; z-index: -1; border-color: transparent; outline: none; color: transparent; background-color: transparent;" />

"position" , , "" () , "z-index" , ( , libgdx). , , .

  1. <head> script:

<script type="text/javascript"> window.onkeydown = function(e) { if(e.keyCode == 32) { document.getElementById("shazam").focus(); } }; window.onscroll = function(e){ document.getElementById("shazam").style.top=window.pageYOffset+"px"; }; </script>

, . Google Chrome.

, , ... , .

----

, .

0

All Articles