feat(#8): move listeners to load
This commit is contained in:
parent
c1fe3acc11
commit
4e2905cf96
1 changed files with 9 additions and 6 deletions
5
index.js
5
index.js
|
@ -38,18 +38,21 @@ class Game extends GameObject {
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
this.ctx = this.canvas.getContext("2d");
|
this.ctx = this.canvas.getContext("2d");
|
||||||
this.lastTime = 0;
|
this.lastTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
async load() {
|
||||||
|
await super.load();
|
||||||
clicableObjects.forEach((elementId) => {
|
clicableObjects.forEach((elementId) => {
|
||||||
document.getElementById(elementId).addEventListener("click", () => {
|
document.getElementById(elementId).addEventListener("click", () => {
|
||||||
this.onMouseClick(elementId);
|
this.onMouseClick(elementId);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
document.addEventListener("keydown", (event) => {
|
document.addEventListener("keydown", (event) => {
|
||||||
this.onKeyPressed(event.key);
|
this.onKeyPressed(event.key);
|
||||||
});
|
});
|
||||||
document.addEventListener("keyup", (event) => {
|
document.addEventListener("keyup", (event) => {
|
||||||
this.onKeyReleased(event.key);
|
this.onKeyReleased(event.key);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clear(ctx) {
|
clear(ctx) {
|
||||||
|
|
Loading…
Reference in a new issue