Timer and detecting collision? Help pls

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
Dr Holy Bacon
Prole
Posts: 1
Joined: Tue Jul 01, 2014 10:00 am
Location: United Kingdom

Timer and detecting collision? Help pls

Post 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 :)
Attachments
main.lua
(9.67 KiB) Downloaded 117 times
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Timer and detecting collision? Help pls

Post 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.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Timer and detecting collision? Help pls

Post by Jasoco »

You can also use a timer library like Cron to make timers easier to understand and use.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests