Discuss Scratch

TheParlight
Scratcher
47 posts

Can someone explain how an FPS counter works?

Hi!

I was planning on implementing an FPS counter into my project just for my own testing to see how much the clones and whatnot affect my device (which is pretty average and standard as far as specs go). I have no idea how an FPS counter works though, the concept of it is just very foreign to me. I've seen so many tutorials, all of which give you a handed group of blocks and call it educational. I didn't learn anything but how to copy the blocks.

So my question is how does it work? What exactly happens in an FPS counter for it to properly display the number of frames?
CatsUnited
Scratcher
1000+ posts

Can someone explain how an FPS counter works?

It runs in a loop with no wait blocks. There's a counter, which runs until a timer hits 1.0. Then, the result of the counter goes to the FPS variable.
Znapi
Scratcher
500+ posts

Can someone explain how an FPS counter works?

FPS means frames per second. For FPS counters in Scratch, a frame is usually considered one run through a loop. A single run through a loop is also called an iteration, just in case you hear that somewhere too.
forever
do stuff
...
change [frame count / number of loop iterations v] by (1) // every time you reach the end of the loop, count it as one frame
end
That is how you can count the number of frames your project is doing. Since FPS means frames per second, every second you need to display how many frames were counted each second. That is where the timer comes in. Every 1 second, you record how many frames were counted, and reset both the timer and frame counter variable to 0 to start counting all over again.
forever
...
change [frame count / number of loop iterations v] by (1) // every time you reach the end of the loop, count it as one frame
if<<(timer) = (1)> or <(timer) > (1)>> // if a second has gone by
set [FPS v] to (frame count / number of loop iterations :: variables) // record how many frames were counted this second (this is the variable showing on the stage)
reset timer // reset the timer and counter to 0
set [frame count / number of loop iterations v] to (0)
end
end
This is probably the simplest FPS counter you can make in Scratch. This can be expanded upon, and might have to be if you are using the timer somewhere else in your project. Note that this works best if you have only one main loop running in your project, because you only have to count the frames for that one loop. If you don't have one main loop, you can put a different FPS counter in each loop, but I don't know how meaningful the results will be.
TheParlight
Scratcher
47 posts

Can someone explain how an FPS counter works?

Znapi wrote:

FPS means frames per second. For FPS counters in Scratch, a frame is usually considered one run through a loop. A single run through a loop is also called an iteration, just in case you hear that somewhere too.
forever
do stuff
...
change [frame count / number of loop iterations v] by (1) // every time you reach the end of the loop, count it as one frame
end
That is how you can count the number of frames your project is doing. Since FPS means frames per second, every second you need to display how many frames were counted each second. That is where the timer comes in. Every 1 second, you record how many frames were counted, and reset both the timer and frame counter variable to 0 to start counting all over again.
forever
...
change [frame count / number of loop iterations v] by (1) // every time you reach the end of the loop, count it as one frame
if<<(timer) = (1)> or <(timer) > (1)>> // if a second has gone by
set [FPS v] to (frame count / number of loop iterations :: variables) // record how many frames were counted this second (this is the variable showing on the stage)
reset timer // reset the timer and counter to 0
set [frame count / number of loop iterations v] to (0)
end
end
This is probably the simplest FPS counter you can make in Scratch. This can be expanded upon, and might have to be if you are using the timer somewhere else in your project. Note that this works best if you have only one main loop running in your project, because you only have to count the frames for that one loop. If you don't have one main loop, you can put a different FPS counter in each loop, but I don't know how meaningful the results will be.
Wow, thanks! (:

Powered by DjangoBB