[FIXED] Previous bug fixed
This commit is contained in:
parent
e90a424e54
commit
86e0b45a2f
@ -11,17 +11,21 @@ export function init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Game {
|
export class Game {
|
||||||
|
_pageIsInView = true;
|
||||||
|
|
||||||
constructor(width = 416, height = 416, ctx) {
|
constructor(width = 416, height = 416, ctx) {
|
||||||
this.gameField = new GameField(width, height, ctx, canvas);
|
this.gameField = new GameField(width, height, ctx, canvas);
|
||||||
this.gameKeyAdapter = new TankKeyAdapter(this.gameField.tank);
|
this.gameKeyAdapter = new TankKeyAdapter(this.gameField.tank);
|
||||||
|
|
||||||
|
window.addEventListener("blur", () => { this._pageIsInView = false; });
|
||||||
|
window.addEventListener("focus", () => { this._pageIsInView = true; });
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
let prevEv;
|
let prevEv;
|
||||||
let holding = (ev) => {
|
let holding = (ev) => {
|
||||||
if (!prevEv || prevEv.key != ev.key) return;
|
if (!prevEv || prevEv.key != ev.key) return;
|
||||||
if (document.visibilityState == "hidden") {
|
if (!this._pageIsInView) {
|
||||||
alert("I'm hidden");
|
|
||||||
prevEv = undefined;
|
prevEv = undefined;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user