Hi,
Its been a week of learning corona sdk.
I am finding it interesting. I want to set a countdown timer on my game screen for sixty seconds.
Also, I want the score to appear
Thanks in Advance!
Hi,
Its been a week of learning corona sdk.
I am finding it interesting. I want to set a countdown timer on my game screen for sixty seconds.
Also, I want the score to appear
Thanks in Advance!
You will use display.newText() API to create a text object to show your timer. You will update it using its .text property. You will need a variable to hold the counter for the time and initialize it to 60 (you will probably simply assign the value of this counter to your display.newText()'s .text property to updated.
Then you will use timer.performWithDelay(1000, updateTime, 60) api call. This says every 1000 milliseconds, call a function updateTime() that you have to write and do this 60 times.
Your updateTime function is where you will take your counter, subtract 1 from it then take the new counter and stick it into your text object’s .text attribute.
Simple countdown timer.
Score will need a display.newText() object and a variable to hold the actual score. When you update the score, set the display.newText() object’s .text attribute with the value of the score.
I had applied the same logic for timer. But the text is getting overlapped.

That sounds like you are creating multiple display.newText() objects. You just create it once, outside of the update function.
[lua]
local counter = 60
local timeDisplay = display.newText(counter,0,0,native.systemFrontBold,64)
timeDisplay.x = display.contentCenterX
timeDisplay.y = 100
local function updateTimer(event)
counter = counter - 1
timeDisplay.text = counter
if counter == 0 then
– do what you want to do when the timer ends
end
end
timer.performWithDelay(1000, updateTimer, 60)
[/lua]
Thanks.
You will use display.newText() API to create a text object to show your timer. You will update it using its .text property. You will need a variable to hold the counter for the time and initialize it to 60 (you will probably simply assign the value of this counter to your display.newText()'s .text property to updated.
Then you will use timer.performWithDelay(1000, updateTime, 60) api call. This says every 1000 milliseconds, call a function updateTime() that you have to write and do this 60 times.
Your updateTime function is where you will take your counter, subtract 1 from it then take the new counter and stick it into your text object’s .text attribute.
Simple countdown timer.
Score will need a display.newText() object and a variable to hold the actual score. When you update the score, set the display.newText() object’s .text attribute with the value of the score.
I had applied the same logic for timer. But the text is getting overlapped.

That sounds like you are creating multiple display.newText() objects. You just create it once, outside of the update function.
[lua]
local counter = 60
local timeDisplay = display.newText(counter,0,0,native.systemFrontBold,64)
timeDisplay.x = display.contentCenterX
timeDisplay.y = 100
local function updateTimer(event)
counter = counter - 1
timeDisplay.text = counter
if counter == 0 then
– do what you want to do when the timer ends
end
end
timer.performWithDelay(1000, updateTimer, 60)
[/lua]
Thanks.