I have this piece of code:
var framerate = 120;
function setup() {
createCanvas(1920, 1080);
frameRate(framerate);
}
function draw() {
clear();
textSize(13);
text(frameRate(), 20, 20);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.11.0/p5.js"></script>
I want it to set the maximum frameRate to 120, and then display the current frameRate at the top right of the canvas. However, it is currently displaying numbers from 163 to 170. This shouldn't be my frameRate, as I set the maximum to 120 in the setup function.
frameRate()with one numeric argument, as inframeRate(30), attempts to draw 30 frames per second (FPS). The target frame rate may not be achieved depending on the sketch's processing needs. Most computers default to a frame rate of 60 FPS. Frame rates of 24 FPS and above are fast enough for smooth animations. CallingframeRate()without an argument returns the current frame rate. The value returned is an approximation."requestAnimationFrame()with the interval you need (120Hz)). Also, if p5.js isn't a must you can test a separate library such as pixi.js. (The API may not as novice friendly, however they have a lot of examples to get started and are performance oriented). HTH