This is in Frames per Second, not feet per second Ahem, chipguy
Jk.
Here ya' go people:
when gf clicked forever set [FPS v] to ((1)/(timer)) reset timerYou can tell this is an accurate showing because:
when gf clicked forever change [frame v] by (1) if < (timer) > [1] > set [FPS v] to (frame) set [frame v] to (0) reset timer endThe second one is rounded. The first one is exact and refreshed every frame, not every second like the second one. Hope you find this useful!
Last edited by chanmanpartyman (2012-04-15 20:57:54)
Offline
beyblade4 wrote:
what is this for?
Usually someone uses an FPS simply for displaying it to the user...it allows them to know the speed the program is running at. You could use the FPS to possibly try and keep your project going at a constant FPS by adding a system that waits until it's to a set value as well
Offline
chipguy wrote:
nice script! i wonder how someone would use it, though.
For instance, if you want a sprite to move at a constant speed in real time, you could make it move at a speed that is a function of the FPS (if that makes sense). The less frames per second you have, the faster the sprite moves per frame; this means that in "real time" it moves a constant speed.
Having said all of that, I've never used it in Scratch
Offline
I thought this was a first-person shooter
Offline
It is especially useful if you want to create a project that is meant to run in turbo mode, and you want to run the project at a steady 30 frames per second, for example. You run the game loop that gathers input from the user, etc. (this gives you faster responses), but you only update the position of the sprite when the FPS script returns a value greater than 30.
For example:
when gf clicked set [Framerate v] to (30) forever broadcast [GetKeyPresses v] and wait // The program collects keypresses. broadcast [Update v] and wait // The program carries out any calculations needed. set [FPS v] to ((1)/(timer)) if < (FPS) > (Framerate) > broadcast [Draw v] and wait // Game elements change position on screen. end end
Last edited by amcerbu (2012-04-23 11:34:10)
Offline
It can also be used simply to check if the project is in turbo mode: run it a few times on non-turbo mode, check the peak fps, add this script:
when gf clicked if <(fps) < [peak fps]> say [I'm in turbo mode!] else say [I'm not in turbo mode...] end
Last edited by Hardmath123 (2012-04-23 12:22:51)
Offline
@Hardmath123- Wouldn't it be the opposite, because you would expect the framerate to go up in turbo mode?
So...
when gf clicked set [highestFramerate v] to (0) repeat (10) set [framerate v] to ((1)/(timer)) if <(framerate) > (highestFramerate)> set [highestFramerate v] to (framerate) end reset timer end if <(highestFramerate) > (fpsTurbo)> say [I'm in turbo mode!] else say [I'm not in turbo mode...] end
Last edited by amcerbu (2012-04-23 18:44:10)
Offline