From 14bc83125c72304f22a65cd28daa9318775d3ad0 Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Wed, 1 Jan 2020 00:29:41 +0200 Subject: [PATCH] set text on the fly, fps count --- src/engine/gui/font.js | 5 +++++ src/index.js | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/engine/gui/font.js b/src/engine/gui/font.js index 6d523be..0a1e03f 100644 --- a/src/engine/gui/font.js +++ b/src/engine/gui/font.js @@ -348,6 +348,11 @@ class GUIText extends Node2D { } } + setText (str) { + this.text = str + this.mesh = null + } + createMesh (gl) { this.mesh = this.font.createTextMesh(gl, this) } diff --git a/src/index.js b/src/index.js index 9f10d6f..af92f0d 100644 --- a/src/index.js +++ b/src/index.js @@ -53,7 +53,7 @@ async function pipeline () { new Dim4(-0.9, 0.0, 0.9, 0.0), new Dim4(0.1, 0.0, 0.1, 0.0)) ] // Nesting test - itms[0].addChild(new GUIText('this project is coded by an idiot', arialFont, 1.5, new Dim4(0.1, 0.0, -0.1, 0.0), new Dim4(1.0, 0.0, 0.3, 0.0), false)) + itms[0].addChild(new GUIText('this project is coded by an idiot', arialFont, 0.8, new Dim4(0.2, 0.0, 0.0, 0.0), new Dim4(1.0, 0.0, 0.3, 0.0), false)) itms[0].children[0].color = [0.0, 0.2, 1.0] // Create a height map based on OpenSimplex noise @@ -86,6 +86,7 @@ async function pipeline () { await skybox.initialize(game.gl) // Update function for camera and terrain + let fpsTimer = 0 game.addUpdateFunction(function (dt) { if (game.input.isDown('w')) { cam.processKeyboard(0, dt) @@ -123,6 +124,13 @@ async function pipeline () { // Ripple water water.update(dt) + + // Set text to FPS + fpsTimer++ + if (fpsTimer === 10) { + itms[0].children[0].setText(game.fps + ' fps') + fpsTimer = 0 + } }) function drawEverything (gl) {