I have a loading bar that serves as a timer, and I have tried to set up some code to have it reset when the bar runs out, and repeat this pattern infinitely, but once it runs out the first time, it does not reset.
local time = 15000 local count = 100 local bar = display.newRect(60, 165, 280, 20) bar.anchorX = 0 --Show a basic white bar local timeBar = display.newRect( 60, 165, 278, 20 ) timeBar:setFillColor(0, 0, 1) timeBar.anchorX = 0 timeBar.y = 165 function resetTimer() timeBar.width = 278 loseTime() end --Make the bar shrink over time function loseTime (event) timeBar.width = timeBar.width - 2.8 timeBar.anchorX = 0 count = count - 1 if count == 99 then timer.performWithDelay(time + time/10, resetTimer, 1) end if count == 0 then local gameTimer = timer.performWithDelay(time/100, loseTime, 100) end end local gameTimer = timer.performWithDelay(time/100, loseTime, 100)
Please compile this code to see for yourself. Thanks in advance!