set text on the fly, fps count

This commit is contained in:
Evert Prants 2020-01-01 00:29:41 +02:00
parent 6eaf11cc02
commit 14bc83125c
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 14 additions and 1 deletions

View File

@ -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)
}

View File

@ -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) {