Slowing it down

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
SamPerson12345
Prole
Posts: 41
Joined: Sat Aug 30, 2008 5:35 pm

Slowing it down

Post 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:
Green_Hell
Citizen
Posts: 94
Joined: Thu Feb 21, 2008 1:11 am

Re: Slowing it down

Post 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.
>>I love LÖVE.<<
User avatar
SamPerson12345
Prole
Posts: 41
Joined: Sat Aug 30, 2008 5:35 pm

Re: Slowing it down

Post 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?
surtic
Citizen
Posts: 74
Joined: Sat Jul 12, 2008 12:18 am

Re: Slowing it down

Post 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).
Post Reply

Who is online

Users browsing this forum: No registered users and 55 guests