Skip to content

Instantly share code, notes, and snippets.

@yearofthewhopper
Forked from lassemt/script.js
Created September 27, 2020 22:33
Show Gist options
  • Save yearofthewhopper/401f584032498c5463105cbeca826e60 to your computer and use it in GitHub Desktop.
Save yearofthewhopper/401f584032498c5463105cbeca826e60 to your computer and use it in GitHub Desktop.
SparkAR requestAnimationFrame alternative.
const t = require('Time');
const D = require('Diagnostics');
const Scene = require('Scene');
const objText = Scene.root.find('2dText0');
let frame = 0;
const round = (val, precision = 1) => {
const multiplier = Math.pow(10, precision || 0);
return Math.round(val * multiplier) / multiplier;
}
t.ms.monitor().subscribe(evt => {
frame++;
objText.text = `FPS: ${round(frame / (evt.newValue / 1000))}`
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment