Skip to content

Instantly share code, notes, and snippets.

@roulupen
Created July 30, 2013 10:46
Show Gist options
  • Save roulupen/6111952 to your computer and use it in GitHub Desktop.
Save roulupen/6111952 to your computer and use it in GitHub Desktop.
Code block in lua file
– Define a group
local gameBoardGroup = display.newGroup()
– Define background to display count down
local countDownOverlay = display.newRect(0, 0, displayWidth, displayHeight)
countDownOverlay:setFillColor(140, 140, 140) – Set the color of the block
countDownOverlay.alpha = 0.5 – Define opacity to make it translucent
– Insert backround to the display group
gameBoardGroup : insert( countDownOverlay )
– Define label to display number
local countDownText = display.newText( “”,0, 0, native.systemFont, displayHeight * 0.5 )
countDownText:setTextColor( 131, 255, 131 )
– Define text color
countDownText:setReferencePoint( display.TopLeftReferencePoint ) – Define text position reference
– Insert text to the display group
gameBoardGroup : insert( countDownText )
– Set the text position at center
countDownText.x = ((displayWidth * 0.5) – (countDownText.contentWidth * 0.5))
countDownText.y = ((displayHeight * 0.5) – (countDownText.contentHeight * 0.5))
– Define count down number
local countDownNum = 3
– Define function to show countdown numbers
local showCountDown = function()
– Condition to show and hide countdown
if countDownNum == 0 then
countDownText:removeSelf() – Remove countdown text
countDownOverlay:removeSelf() – Remove countdown background
– TODO : Code to start the game
else – Condition to display countdown numbers
countDownText.text = countDownNum
end
countDownNum = countDownNum – 1
end
– Defined timer to strat the countdown
timer.performWithDelay( 1000, showCountDown, 4 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment