using timer for game start countdown - counter suddenly speeds up?

I have a start screen displaying a counter label and a start button.
the label should be displaying the countdown to start the game when the start button is touched and it does that, mostly… the timer display sits on 3 for a moment then speeds through 2 and 1. Anyone come across this behavior before?

3…21GO

relevant code:
[lua]local function countdownHandler()

startCount = startCount - 1
lblStartCount.text = startCount
if startCount == 0 then
scrnStartCount.x = display.contentWidth*-1
–start game timer
state = “running”
if gTimer ~= nil then
gTimer:start()
end
end
end

local function Hndlr_btnStart(event)
–start countdown timer
timer.performWithDelay(1000,countdownHandler,3)
end[/lua] [import]uid: 78339 topic_id: 14557 reply_id: 314557[/import]

Ignoring the fact that I threw orange.png in there to test (lol), does this perform as expected for you, or does it still rush through? For me, it’s performing fine, no rush;

[lua]local lblStartCount = display.newText(“3”, 100, 100, systemDefault, 18)

startCount = 3

local scrnStartCount = display.newImage(“orange.png”)

local function countdownHandler()

startCount = startCount - 1
lblStartCount.text = startCount
if startCount == 0 then
scrnStartCount.x = display.contentWidth*-1
–start game timer
state = “running”
if gTimer ~= nil then
gTimer:start()
end
end
end

local function Hndlr_btnStart(event)
–start countdown timer
timer.performWithDelay(1000,countdownHandler,3)
end

Hndlr_btnStart()[/lua]

What version of Corona are you running and on what kind of machine?

Peach [import]uid: 52491 topic_id: 14557 reply_id: 53888[/import]

That works as expected. The only difference I can think of is that you are calling the Hndlr_btnStart() function directly while I am calling it from a button click but I’m not sure why that would cause this kind of problem. Any Ideas?

Thanks for the response!
I’m using Version: 2.0.0 Build: 2011.505
on Win XP Pro sp2 [import]uid: 78339 topic_id: 14557 reply_id: 53996[/import]

Ok so the button *does* make a huge difference. I’m not sure why I didn’t think of this to begin with. Touch events in the simulator are getting triggered twice per click; once on mouse down, once on mouse up. So, when I click my start button the Hndlr_btnStart() gets called twice. I’ve accounted for this in the rest of my buttons but totally spaced on it this time.

Whats up with the clicking weirdness anyway? Is this normal and I missed it in the docs or is it a bug? [import]uid: 78339 topic_id: 14557 reply_id: 54001[/import]

Hey, a little late - sorry - it occurred to me that you might have been using touch incorrectly.

It is not a bug, touch is ANY touch. Up, down, moving your finger across the button, etc.

Now, you have two options.

Option one is to use “tap” instead of touch;
[lua]local function Hndlr_btnStart(event)
–start countdown timer
timer.performWithDelay(1000,countdownHandler,3)
end
button:addEventListener(“tap”, Hndlr_btnStart)[/lua]

Option two is to only fire the event when the touch ends;
[lua]local function Hndlr_btnStart(event)
if event.phase == “ended” then
–start countdown timer
timer.performWithDelay(1000,countdownHandler,3)
end
end
button:addEventListener(“touch”, Hndlr_btnStart)[/lua]

You could also use “began” rather than “ended” if you wanted the timer to start when the button was touched rather than when that touch was released.

Peach :slight_smile: [import]uid: 52491 topic_id: 14557 reply_id: 54041[/import]

Ahh, so it’s normal and I missed it. Happens sometimes…

Thanks for your help! [import]uid: 78339 topic_id: 14557 reply_id: 54060[/import]

Not a problem - everyone has problems like that with touch at first, I think. (I know I did and I know most people I’ve taught about Corona have as well.)

Glad we’ve got it sorted, now :slight_smile: [import]uid: 52491 topic_id: 14557 reply_id: 54153[/import]