Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Simple timer?

edited November 2013 in Questions Posts: 17

Does anyone know how to make a simple timer that shows up on the screen? This is a noobie question but I'm just getting into programming.

Tagged:

Comments

  • edited November 2013 Posts: 577
    function setup()
    time = 0
    end
    
    function draw()
    time = time + 1 -- If you change this to subtracting, then it will count down by one 
    text(time, WIDTH/2, HEIGHT/2)
    end
    
  • BriarfoxBriarfox Mod
    Posts: 1,542

    tween.delay() works well.

    function setup()
        counter = 1
        timer(1,function() counter = counter+1  end)
    end
    
    function draw()
        background(0, 0, 0, 255)
        text("Count is: "..counter,WIDTH/2,HEIGHT/2)
    end
    
    function timer(t,callback)
        tween.delay(t,function() callback() timer(t,callback) end)
    end
    
Sign In or Register to comment.