Discuss Scratch

zekrom1407
Scratcher
28 posts

How to make an FPS counter

The title pretty much says it all. I'm not sure how to make an FPS counter, so can someone help me figure it out maybe?
Flipped_
Scratcher
500+ posts

How to make an FPS counter

Hmm, I've never done it myself, but I would begin with

when green flag clicked
forever
reset timer
repeat until <(timer) > [0.3]>
change [var v] by (1)
end
end

That variable would be the length of time it took for the time to go from 0 to over 0.3, you could take it from there since I'm not sure how I would convert that variable into a framerate.

Last edited by Flipped_ (March 3, 2019 19:58:24)

Kraken_Games
Scratcher
100+ posts

How to make an FPS counter

Aha

(Frames Per Second)
(Counter)

when green flag clicked
forever
set [Frames Per Second v] to [(Counter)]
set [Counter v] to [0]
end

when green flag clicked
forever
change [Counter v] by (1)
end
sippingcider
Scratcher
500+ posts

How to make an FPS counter

FPS stands for Frames Per Second. In other words, how many frames are rendered in one second.

When green flag clicked
reset timer
set [lastFPSUpdate v] to [0]
forever // so the fps continues to get updated
change [frames v] by (1) // 1 frame has been updated
if <(timer) > ((lastFPSUpdate) + (1))> then //checks if it has been 1 second since the last fps update
set [FPS v] to (frames) //number of frame updates that happened during that 1 second
set [frames v] to [0] //reset frames for the next 1 second calculation
set [lastFPSUpdate v] to (timer) //reset our lastFPSUpdate variable for the next 1 second calculation
end
end

Edit: I had a bunch of other stuff written here that wasn't needed, since the forever loop yields this will work fine.

Last edited by sippingcider (March 4, 2019 00:02:12)

gor-dee
Scratcher
1000+ posts

How to make an FPS counter

forever
set [FPS v] to ((1) / (timer))
reset timer
end
put the two blocks at the end of an existing forever loop

Last edited by gor-dee (March 4, 2019 00:51:03)

sippingcider
Scratcher
500+ posts

How to make an FPS counter

gor-dee wrote:

forever
set [FPS v] to ((1) / (timer))
reset timer
end
put the two blocks at the end of an existing forever loop

Oh wow, that is a really elegant way of doing it. You should try doing a scratch-golf competition!
-Snipet-
Scratcher
500+ posts

How to make an FPS counter

gor-dee wrote:

forever
set [FPS v] to ((1) / (timer))
reset timer
end
put the two blocks at the end of an existing forever loop
Wow, that’s efficient
zekrom1407
Scratcher
28 posts

How to make an FPS counter

-Snipet- wrote:

gor-dee wrote:

forever
set [FPS v] to ((1) / (timer))
reset timer
end
put the two blocks at the end of an existing forever loop
Wow, that’s efficient


yeah that is pretty nice
colinmacc
Scratcher
1000+ posts

How to make an FPS counter

I usually put one in all my games, just to check how well it's running. Basically this is the main repeat loop..

reset timer
repeat until <(playing) = [FALSE]>
change [tick v] by (1)
set [FPS v] to (round ((tick) / (round (timer))))
Do everything else...
end

Last edited by colinmacc (March 4, 2019 15:33:05)

MrSquirrelDeDuck
Scratcher
100+ posts

How to make an FPS counter

I agree that
forever
set [FPS v] to ((1) / (timer))
reset timer
end

Is very efficient but it gives you a large decimal, I used

forever
set [FPS v] to (round ((1) / (timer)))
reset timer
end

ZXMBXES
Scratcher
4 posts

How to make an FPS counter

sippingcider wrote:

FPS stands for Frames Per Second. In other words, how many frames are rendered in one second.

When green flag clicked
reset timer
set [lastFPSUpdate v] to [0]
forever // so the fps continues to get updated
change [frames v] by (1) // 1 frame has been updated
if <(timer) > ((lastFPSUpdate) + (1))> then //checks if it has been 1 second since the last fps update
set [FPS v] to (frames) //number of frame updates that happened during that 1 second
set [frames v] to [0] //reset frames for the next 1 second calculation
set [lastFPSUpdate v] to (timer) //reset our lastFPSUpdate variable for the next 1 second calculation
end
end


-InsanityPlays-
Scratcher
1000+ posts

How to make an FPS counter

Here's a simple one. Go to the backdrop sprite and make two backdrops then make this:
when green flag clicked
forever
switch backdrop to [backdrop1 v]
switch backdrop to [backdrop2 v]
end
when backdrop switches to [backdrop1 v]
reset timer
when backdrop switches to [backdrop2 v]
set [fps v] to ((1)/(timer))

Last edited by -InsanityPlays- (June 11, 2020 10:08:28)

Lightthefox
Scratcher
13 posts

How to make an FPS counter

i have found a method that works in scratch 2 and 3
when green flag clicked
forever
change [count v] by (1)
wait (0) secs
if <(timer) > [1]> then
reset timer
set [fps v] to [count]
set [count v] to [0]
end
end
i can not put the flag on the other stuff sorry but here is a picture for scratch 3 it is exactly the same

Last edited by Lightthefox (July 29, 2020 06:35:09)

maDU59_
Scratcher
59 posts

How to make an FPS counter

gor-dee wrote:

forever
set [FPS v] to ((1) / (timer))
reset timer
end
put the two blocks at the end of an existing forever loop
Very usualy
Vanilla2011
Scratcher
500+ posts

How to make an FPS counter

gor-dee wrote:

forever
set [FPS v] to ((1) / (timer))
reset timer
put the two blocks at the end of an existing forever loop
Who are you, so wise in the ways of Scratch coding?
THECODEWARRIORS
Scratcher
100+ posts

How to make an FPS counter

I have made a fps and turbo mode detector engine here you go - https://scratch.mit.edu/projects/422364988/
dominic305
Scratcher
500+ posts

How to make an FPS counter

Here's a way that doesn't require the timer to be reset:
when gf clicked
set [oldTimer v] to [0]
forever
set [FPS v] to (round([1]/((timer)-(oldTimer)))
set [oldTimer v] to (timer)
end
WolfMike6
Scratcher
100+ posts

How to make an FPS counter

I dont know how to make on either. i want to know!





https://scratch.mit.edu/studios/27775551/projects/


the best game series ever!

Powered by DjangoBB