浏览代码

✨ Make stuff work on WebGl mode

- TODO: copy a default font to pandora for the engine to use.
Pedro Schneider 3 年之前
父节点
当前提交
32102e8790
共有 3 个文件被更改,包括 31 次插入6 次删除
  1. 5 0
      pandora/Enums.js
  2. 0 4
      pandora/game_objects/GameObject.js
  3. 26 2
      pandora/handlers/GameHandler.js

+ 5 - 0
pandora/Enums.js

@@ -1,4 +1,9 @@
 const SHAPES = {
     RECT: 1,
     ELLIPSE: 2,
+}
+
+const RENDER_MODES = {
+    P2D: 1,
+    WEBGL: 2,
 }

+ 0 - 4
pandora/game_objects/GameObject.js

@@ -14,10 +14,6 @@ class GameObject
 
     }
 
-
-
-
-
     // Getters
     getChildren()
     {

+ 26 - 2
pandora/handlers/GameHandler.js

@@ -3,12 +3,34 @@ class GameHandler
     static rootObjects = []
     static nextId = 0;
 
+    static renderMode = null;
+    static setRenderMode(mode)
+    {
+        this.renderMode = mode;
+    }
+
     static bDrawDebugFPS = false;
     static drawDebugFPS(val)
     {
         this.bDrawDebugFPS = val;
     }
 
+    static init()
+    {
+        if (!this.renderMode) this.renderMode = RENDER_MODES.P2D;
+        switch (this.renderMode)
+        {
+            case RENDER_MODES.P2D:
+                createCanvas(windowWidth, windowHeight);
+                break;
+            case RENDER_MODES.WEBGL:
+                createCanvas(windowWidth, windowHeight, WEBGL);
+                break;
+
+        }
+        smooth();
+    }
+
     static instanceGameObject(obj)
     {
         obj.id = this.nextId;
@@ -28,11 +50,13 @@ class GameHandler
 
     static draw()
     {
+        if (this.renderMode == RENDER_MODES.WEBGL) translate(-windowWidth / 2, -windowHeight / 2);
         if (this.bDrawDebugFPS)
         {
             textSize(12);
-            stroke(0);
-            text("FPS: " + frameRate(), 10, 10, windowWidth, windowHeight);
+            noStroke();
+            fill(0);
+            text("FPS: " + frameRate(), 10, 20);
         }
 
         for (let i = 0; i < this.rootObjects.length; i++)