I'm currently working on a projectile motion game in scratch, and I'm wondering how it works when it comes to frames. Does scratch keep a constant FPS? If not, is there a way to implement an accurate deltatime approach to this problem? I have only been able to get a deltatime between frame of .1 seconds. I hope someone can help me with this! Thanks!
Offline
I don't think it has a set framerate. Every single image-manipulative block is done completely, before it moves onto the next block (I'm pretty sure, although I could be wrong since I don't see the source of scratch a lot).
If you want to be able to control the frame rate, you could just have all the rendering scripts run at around the same time (you would need to have either a bunch of broadcast and wait's running in sequence, or just a 1 sprite 1 script project), and to slow it down put wait blocks.
Offline
I'd imagine that could get buggy.. Normally what is done in programming if the update isn't set you get the change in time between two frames then multiply the movement of an object by that time to keep it consistent, but the timer only keeps track out to on decimal point of accuracy. I need three decimal points for this method to work. Any ideas of how to get more accuracy in measurements?
Thanks,
Cody
Offline
codeblue wrote:
I'd imagine that could get buggy.. Normally what is done in programming if the update isn't set you get the change in time between two frames then multiply the movement of an object by that time to keep it consistent, but the timer only keeps track out to on decimal point of accuracy. I need three decimal points for this method to work. Any ideas of how to get more accuracy in measurements?
Thanks,
Cody
Instead of using Scratch's timer, you could create an artificial timer, though this isn't too much more accurate. In fact, it's only accurate to the fortieth of a second. Anyway, here's the script for the artificial timer:
when gf clicked set [timer v] to (0) forever change [timer v] by (.025)I hope that this helps!
Last edited by ErnieParke (2012-11-18 15:34:06)
Offline
codeblue wrote:
I'd imagine that could get buggy.. Normally what is done in programming if the update isn't set you get the change in time between two frames then multiply the movement of an object by that time to keep it consistent, but the timer only keeps track out to on decimal point of accuracy. I need three decimal points for this method to work. Any ideas of how to get more accuracy in measurements?
Thanks,
Cody
Actually, the timer goes out towards the third decimal place, it only shows towards the first decimal place in the displayer, but if you put it in a list display, it goes until the third decimal, and the timer reporter will report in the third decimal. So your way can work.
Offline
On average, of course!
Offline
Thanks everyone for your replies. Apparently the fps implementation will not work in scratch for whatever reason. I have conceded to a fall back method where I simply calculate the position of the object based on the formulas of newtons law of motion instead of incrementing the acceleration every frame. Thanks again for your input!
Offline
Were you talking about using Euler's method for integration? I made a project that uses integration to calculate the position of a projectile, which worked OK. I'll post the script if you want.
Offline