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