Thought I'd post this - the code from one of my apps. It counts down in seconds then shows a message then removes the message.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | local timerCount = 20; -- how many seconds to count down local textToShow = display.newText("", 10,10,'arial', 100); local function clearText() textToShow.text = ''; end local function showText(someText,size,removeAfter) textToShow.size = size; textToShow.text = someText; textToShow:setReferencePoint(display.CenterReferencePoint); textToShow.x = 480/2; textToShow.y = 320/2; if(removeAfter ~= nil) then timer.performWithDelay(1000, clearText, 1); end end local function reduceTime() timerCount = timerCount -1; showText(timerCount, 200); if(timerCount == 0) then showText("The Monsters Are Coming!", 40, 1000); -- text, size, remove after end end showText(timerCount,200); local countDown = timer.performWithDelay(1000, reduceTime, timerCount); |
Nice stuff, I'm sure it will help some people :) I see a few questions from time to time asking about this kind of thing.
Thanks for sharing!
Peach :)