timer pouse and timer restart

local buttonPouse = widget.newButton({

with = 50,

height = 50,

defaultFile = “buttons/pause.png”,

overFile = “buttons/pause1.png”,

onEvent= onEventListenerPouse

})

buttonPouse.x = 900

buttonPouse.y = 60

sceneGroup:insert (buttonPouse)

local secondsLeft = 3 * 60  

local clockText = display.newText(“3:00”, display.contentCenterX, 30, “BrainFlowerEuro.ttf”, 40)

clockText:setFillColor( 0.7, 0.7, 1 )

local function updateTime()

secondsLeft = secondsLeft - 1

local minutes = math.floor( secondsLeft / 60 )

local seconds = secondsLeft % 60

local timeDisplay = string.format( “%02d:%02d”, minutes, seconds )

clockText.text = timeDisplay

end

local countDownTimer = timer.performWithDelay( 1000, updateTime, secondsLeft )

sceneGroup:insert(clockText)

end

Hi,

Please ask the question properly.

Don’t thrown the code unproperly like garbages lol.

What’s the question exactly ? To pause and restart the timer when you press the boutton widget ?

If it’s that, just make your onEventListenerPouse function like that with the variable “countDownTimer” declare below, 

local countDownTimer local function onEventListenerPouse(event) if countDownTimer.\_expired == true then print("time finish - timer expired") return end local ph=event.phase if ph=="began" then timer.pause(countDownTimer) end if ph=="ended" or ph=="cancelled" then timer.resume(countDownTimer) end end

Yvan.

Hi,

Please ask the question properly.

Don’t thrown the code unproperly like garbages lol.

What’s the question exactly ? To pause and restart the timer when you press the boutton widget ?

If it’s that, just make your onEventListenerPouse function like that with the variable “countDownTimer” declare below, 

local countDownTimer local function onEventListenerPouse(event) if countDownTimer.\_expired == true then print("time finish - timer expired") return end local ph=event.phase if ph=="began" then timer.pause(countDownTimer) end if ph=="ended" or ph=="cancelled" then timer.resume(countDownTimer) end end

Yvan.