Page 1 of 1
Slowing it down
Posted: Sat Aug 30, 2008 8:21 pm
by SamPerson12345
I'm working on a love game, but it goes way too fast. Does any one know how I can make it so that a section of code happens about once every half second? help would be greatly appreciated. :mrgreen:
Re: Slowing it down
Posted: Sat Aug 30, 2008 8:42 pm
by Green_Hell
Don't know what you mean but it sounds that you are not using delta time.
If you don't know what I mean than you should see Mike's
screencast and read the documentation.
Otherwise you should provide some code example or better explanation.
Re: Slowing it down
Posted: Sat Aug 30, 2008 9:08 pm
by SamPerson12345
Wait, I got it now.
Code: Select all
function update(dt)
time = dt + time
if time > .5 then
function()
time = 0
end
end
that will work right?
Re: Slowing it down
Posted: Sat Aug 30, 2008 9:46 pm
by surtic
I tend to use something very similar:
Code: Select all
function update(dt)
time = dt + time
if time > .5 then
function()
time = time - .5
end
end
That way, even if update() is called at irregular intervals, function() will still be called the right number of times. It may not make much difference with 0.5s, but if you're trying to get something to happen 20 times a second then resetting time could cause it to be called an unpredictable number of times a second (if update() is called every 0.02 second, function() will be called about 17 times a second - once every 0.06s instead of once every 0.05s. If you keep the remainder it will be called 20 times a second, every 0.06s and 0.04s).