Corona SDK / simple Stopwatch (milliseconds/seconds/minutes)

337 Views Asked by At

right now I am programming a mobile app. I use Corona SDK.

I want to make a simple stopwatch. It should count up in milliseconds, seconds and minutes. I googled it already but all examples I found weren't working for me.

I know there is a way to program a stopwatch but my idea would be very costly. I know Corona is great and I believe that there is a simple and good way to solve my problem. :)

Thanks for helping!

1

There are 1 best solutions below

0
On

Without going in too much detail here, you could use this to count the milliseconds:

local milis = 0
local incrementMilis = 100
local watch

local function updateTime()
    milis = milis + incrementMilis
    --Have some condition to cancel the timer to avoid it running forever
    if someCondition == true then
        timer.cancel(watch)
    end
end

--trigger every 100ms, call 'updateTime' function, and loop forever (-1)
watch = timer.performWithDelay( incrementMilis, updateTime, -1 )

Convert the milis variable however you want to display it by using some simple math functions. This you should be able to figure out yourself and there's enough code and examples online on how to do this.