[FIXED] Previous bug fixed

This commit is contained in:
Nikita Iryupin 2021-05-03 16:25:22 +02:00
parent e90a424e54
commit 86e0b45a2f

View File

@ -11,17 +11,21 @@ export function init() {
}
export class Game {
_pageIsInView = true;
constructor(width = 416, height = 416, ctx) {
this.gameField = new GameField(width, height, ctx, canvas);
this.gameKeyAdapter = new TankKeyAdapter(this.gameField.tank);
window.addEventListener("blur", () => { this._pageIsInView = false; });
window.addEventListener("focus", () => { this._pageIsInView = true; });
}
start() {
let prevEv;
let holding = (ev) => {
if (!prevEv || prevEv.key != ev.key) return;
if (document.visibilityState == "hidden") {
alert("I'm hidden");
if (!this._pageIsInView) {
prevEv = undefined;
return;
}