[BUG} Trying fix pressing buttons out of focus

This commit is contained in:
Nikita Iryupin 2021-05-03 14:33:06 +02:00
parent b4f1e7c083
commit e90a424e54
2 changed files with 11 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import { GameField } from "./Graphics/gameField";
import { GameField } from "./GameLogic/gameField";
import { TankKeyAdapter } from "./KeyAdapters/tankKeyAdapter";
export function init() {
@ -20,6 +20,11 @@ export class Game {
let prevEv;
let holding = (ev) => {
if (!prevEv || prevEv.key != ev.key) return;
if (document.visibilityState == "hidden") {
alert("I'm hidden");
prevEv = undefined;
return;
}
this.gameKeyAdapter.handleEvent(ev)
requestAnimationFrame(() => holding(ev));
}