# FPS block for snap?

I suggest there should be a new block that reports the current Frames Per Second, this could be useful in a lot of ways such as making a script to see when the project is lagging, and turn off some sort of high quality mode that might be in the program, or show the FPS in a counter again when the project is lagging, You could also create an animation that automatically syncs with the FPS to keep it at the same speed.

Why is this a wiki post?

what is a wiki post?

I think I just pressed a button.

Thank You!

How do you use the JS code actually

(function(window, document, undefined){

var canvas       = document.getElementById("mycanvas"),
context      = canvas.getContext("2d"),
width        = canvas.width,
height       = canvas.height,
fps          = 0,
game_running = true,
show_fps     = true;

function showFPS(){
context.fillStyle = "Black";
context.font      = "normal 16pt Arial";

context.fillText(fps + " fps", 10, 26);
}
function gameLoop(){

//Clear screen
context.clearRect(0, 0, width, height);

if (show_fps) showFPS();

if (game_running) requestAnimationFrame(gameLoop);

}

gameLoop();

}(this, this.document))


I don't think this reports a value does it?

it doesn't

I found a solution!
ProjectName=fps
The ones in the aforementioned stackoverflow thread didn't seem to work in Snap!, but this one does. (Keep in mind it will report 0 the first time being called.)

Edit: A weird bug appeared where it reports 20,000 fps after unfocusing and refocusing the page. Don't know why that's happening.

It's not doing that for me.

Huh, when I closed the tab, opened it again and reloaded the project, it didn't happen anymore.
Strange..

The frames block does't relate to frames per second at all. That doesn't work. Besides, it would break anyway if the timer was reset during the code.