소스 검색

♻️ Refactor debug FPS drawing to use new Label object

Pedro Schneider 3 년 전
부모
커밋
0c90d0906e
1개의 변경된 파일5개의 추가작업 그리고 7개의 파일을 삭제
  1. 5 7
      pandora/handlers/GameHandler.js

+ 5 - 7
pandora/handlers/GameHandler.js

@@ -5,6 +5,7 @@ const GameHandler = {
     renderMode: null,
 
     bDrawDebugFPS: false,
+    debugFpsLabel: null,
 
     prevMillis: 0,
     delta: 0,
@@ -34,6 +35,9 @@ const GameHandler = {
         }
         frameRate(fps);
         smooth();
+
+        if (this.bDrawDebugFPS)
+            this.debugFpsLabel = new Label(`FPS: ${frameRate()}`)
     },
 
     instanceGameObject: function(obj)
@@ -49,6 +53,7 @@ const GameHandler = {
 
     update: function()
     {
+        if (this.bDrawDebugFPS) this.debugFpsLabel.setText(`FPS: ${frameRate()}`)
         this.delta = (millis() - this.prevMillis) / 1000;
         for (let i = 0; i < this.rootObjects.length; i++)
             this.rootObjects[i].update(this.delta);
@@ -57,13 +62,6 @@ const GameHandler = {
     draw: function()
     {
         if (this.renderMode == RENDER_MODES.WEBGL) translate(-windowWidth / 2, -windowHeight / 2);
-        if (this.bDrawDebugFPS)
-        {
-            textSize(12);
-            noStroke();
-            fill(0);
-            text("FPS: " + frameRate(), 10, 20);
-        }
 
         for (let i = 0; i < this.rootObjects.length; i++)
             this.rootObjects[i].draw(this.delta);