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 :frowning_face:

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. :confused:

It's not doing that for me. :thinking:

untitled script pic (83)

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.
Please test your solutions before posting them.

Thanks everybody for submiting solutions. I can't handle any more messages from this topic! This was solved by helicopter in post #9 so please do not reply anymore with solutions.

The said script below was the code by helicopter.

It also seems that the FPS is 600, This script would need to be running on a GPU(In Snap! I think everything runs on the CPU except pen and warp)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.