Discuss Scratch

_plaz
Scratcher
23 posts

How do you change x speed by the timer??


i have a set of code where an sprite moves by a current amount of speed

but because scratch is scratch, the sprite sometimes lags out and that messes with the project

i know the timer can fix framerate and stuff, so is there anyway to help stop lag by using the timer someway on this script?
MultiTasker801
Scratcher
100+ posts

How do you change x speed by the timer??

you could use a variable to track the timer and each frame use something like the following to calculate frame time and then figure out how much different every action needs to be
when green flag clicked
forever
set [deltatime v] to ((oldtimer)-(timer))
set [timemultiplier v] to ((deltatime) * [30]) // use this value to change the amount sprites move and such
set [oldtimer v] to (timer)
end
i might be completely mis-interpreting your question, but i think this is the kind of fix you're looking for?
you'll never “fix” lag on scratch but you can always try to work around it
_plaz
Scratcher
23 posts

How do you change x speed by the timer??

MultiTasker801 wrote:

you could use a variable to track the timer and each frame use something like the following to calculate frame time and then figure out how much different every action needs to be
when green flag clicked
forever
set [deltatime v] to ((oldtimer)-(timer))
set [timemultiplier v] to ((deltatime) * [30]) // use this value to change the amount sprites move and such
set [oldtimer v] to (timer)
end
i might be completely mis-interpreting your question, but i think this is the kind of fix you're looking for?
you'll never “fix” lag on scratch but you can always try to work around it
so how would i apply the time multiplier to the “repeat until x pos >” script?

Powered by DjangoBB