Page 1 of 1

Timer and detecting collision? Help pls

Posted: Tue Jul 15, 2014 9:45 am
by Dr Holy Bacon
So I'm making a game where you control a block and gravity changes every time love.update updates 5000 times because I don't know how to make a proper timer. Also the score is supposed to go up when the player touches a specific object. I have found some collision code but the score goes up whenever the player touches any object. My project so far is attached below, any help will be appreciated :)

Re: Timer and detecting collision? Help pls

Posted: Tue Jul 15, 2014 11:20 am
by micha
Here is how you make a timer:

Code: Select all

function love.load()
  timer = 0
  delayTime = 5
end

function love.update(dt)
  timer = timer + dt

  if timer > delayTime then
    timer = timer - delayTime
    doSomeAction()
  end
end
The doSomeAction()-function is called every five seconds.

Re: Timer and detecting collision? Help pls

Posted: Tue Jul 15, 2014 8:19 pm
by Jasoco
You can also use a timer library like Cron to make timers easier to understand and use.