Skip to content

Instantly share code, notes, and snippets.

@figengungor
Created June 9, 2013 23:17
Show Gist options
  • Select an option

  • Save figengungor/5745676 to your computer and use it in GitHub Desktop.

Select an option

Save figengungor/5745676 to your computer and use it in GitHub Desktop.
Countdown App 1, using os.time() and transition.to()
--Countdown App
--os.time() returns the current number of seconds since Jan 1, 1970 to current time
local start=os.time()
local background = display.newImage("background.png")
local W=display.contentWidth
local H=display.contentHeight
--timeIsUp is shown after time is Up, haha
local timeIsUp=display.newText("Time is Up!", 0,0, "James Fajardo", 100)
timeIsUp.x=W/2
timeIsUp.y=H/2
timeIsUp.isVisible=false --timeisUp is hidden at first.
local function countDown(event)
c = 10-(os.time()-start) --for every second, the difference will increase by one between os.time() and start
cText = display.newText(tostring(c), 0, 0 , nil, 100)
cText.x=W/2
cText.y=H/2
transition.to(cText, {time=100, alpha=0}) --when c changes, it changes smoothly by fading away in 100 miliseconds
if(c==0) then --countdown is over
--cleaning time, save some memory
cText:removeSelf()
c=nil
timeIsUp.isVisible=true --time to show up
Runtime:removeEventListener("enterFrame", countDown) --let's stop the enterframe show.
end
end
Runtime:addEventListener("enterFrame", countDown)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment