Jelajahi Sumber

✨ Add pmouseX and pmouseY properties to GameHandler

Pedro Schneider 3 tahun lalu
induk
melakukan
b16662a30d
3 mengubah file dengan 9 tambahan dan 26 penghapusan
  1. 1 1
      pandora.min.js
  2. 8 0
      pandora/handlers/GameHandler.js
  3. 0 25
      src/sketch.js

File diff ditekan karena terlalu besar
+ 1 - 1
pandora.min.js


+ 8 - 0
pandora/handlers/GameHandler.js

@@ -50,6 +50,8 @@ const GameHandler = {
 
     mouseX: 0, // X position of the mouse relative to the secondary buffer.
     mouseY: 0, // Y position of the mouse relative to the secondary buffer.
+    pmouseX: 0, // X position of the mouse relative to the secondary buffer on the previous frame.
+    pmouseY: 0, // Y position of the mouse relative to the secondary buffer on the previous frame.
 
     backgroundColor: null, // Default color to be drawn to the background.
 
@@ -241,6 +243,9 @@ const GameHandler = {
         // Updates the delta.
         this.delta = (millis() - this.prevMillis) / 1000;
 
+        // Update mouse position relative to the secondary buffer.
+        this.pmouseX = this.mouseX;
+        this.pmouseY = this.mouseY;
         let ar = this.db.screenWidth / this.db.width;
         let offsetx = (windowWidth - this.db.screenWidth) / 2;
         let offsety = (windowHeight - this.db.screenHeight) / 2;
@@ -284,6 +289,9 @@ const GameHandler = {
             this.db.screenWidth = windowHeight * (this.dbWidth / this.dbHeight);
         }
 
+        this.db.ellipse(this.pmouseX, this.pmouseY, 20);
+        this.db.line(this.pmouseX, this.pmouseY, this.mouseX, this.mouseY);
+
         // Draw all game objects.
         for (let i = 0; i < this.rootObjects.length; i++)
             this.rootObjects[i].draw(this.delta, this.db);

+ 0 - 25
src/sketch.js

@@ -1,24 +1,5 @@
 let test, test2, but;
 
-class TestObj extends Object2D
-{
-    _setup()
-    {
-        this.getChildByIndex(0).connect("mouseEntered", this, "_onMouseEntered");
-        this.getChildByIndex(0).connect("mouseExited", this, "_onMouseExited");
-    }
-
-    _onMouseEntered()
-    {
-        console.log("hello");
-    }
-
-    _onMouseExited()
-    {
-        console.log("goodbye");
-    }
-}
-
 GameHandler._preload = function()
 {
     AssetHandler.loadTexture("monke", "/assets/textures/monke.png");
@@ -32,10 +13,4 @@ GameHandler._setup = function()
     GameHandler.drawDebugFPS(true);
     GameHandler.drawDebugBufferBounds(true);
     textFont(AssetHandler.getP5FontByName("Lato"));
-
-    test = new Area2D("myTest", SHAPES.ELLIPSE, new Ellipse(200, 400), true, true);
-    test2 = new TestObj("myDummy");
-    test2.setPosition(600, 600);
-    test2.addChild(test);
-    GameHandler.addRootObject(test2);
 }