From 4e2905cf961ef3ddde1739509ecc215353f9e26f Mon Sep 17 00:00:00 2001 From: Juan Sebastian Montoya Date: Sat, 14 Sep 2024 17:43:53 -0500 Subject: [PATCH] feat(#8): move listeners to load --- index.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 97d31b4..8c59081 100644 --- a/index.js +++ b/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); }); }