My code - countdown to the monsters arriving!

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.

[lua]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);[/lua]

Hope it helps someone and *please* let me know any mistakes or improvements I could make.

Thanks

Tom [import]uid: 55068 topic_id: 13692 reply_id: 313692[/import]

Nice stuff, I’m sure it will help some people :slight_smile: I see a few questions from time to time asking about this kind of thing.

Thanks for sharing!

Peach :slight_smile: [import]uid: 52491 topic_id: 13692 reply_id: 50406[/import]