Browse Source

🐛 Update the relative mouse position on update instead of draw

Pedro Schneider 3 years ago
parent
commit
711e86f2d8
1 changed files with 6 additions and 6 deletions
  1. 6 6
      pandora/handlers/GameHandler.js

+ 6 - 6
pandora/handlers/GameHandler.js

@@ -218,6 +218,12 @@ const GameHandler = {
         // Updates the delta.
         this.delta = (millis() - this.prevMillis) / 1000;
 
+        let ar = this.db.screenWidth / this.db.width;
+        let offsetx = (windowWidth - this.db.screenWidth) / 2;
+        let offsety = (windowHeight - this.db.screenHeight) / 2;
+        this.mouseX = (mouseX - offsetx) / ar;
+        this.mouseY = (mouseY - offsety) / ar;
+
         // Updates all game objects on the tree.
         for (let i = 0; i < this.rootObjects.length; i++)
             this.rootObjects[i].update(this.delta);
@@ -253,12 +259,6 @@ const GameHandler = {
             this.db.screenWidth = windowHeight * (this.dbWidth / this.dbHeight);
         }
 
-        let ar = this.db.screenWidth / this.db.width;
-        let offsetx = (windowWidth - this.db.screenWidth) / 2;
-        let offsety = (windowHeight - this.db.screenHeight) / 2;
-        this.mouseX = (mouseX - offsetx) / ar;
-        this.mouseY = (mouseY - offsety) / ar;
-
         // Draw all game objects.
         for (let i = 0; i < this.rootObjects.length; i++)
             this.rootObjects[i].draw(this.delta, this.db);