I have set up a stopwatch timer to play when the game starts and it works well to pause the timer with a button to get the event.time pausedAt = event.time but when the scene:hide is called there’s no event time it seems. Is there another way to get the time it was paused at?
Post code… you probably have a missing var somewhere.
function scene:hide( event ) print(event.time) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen end end
The output is nil.
btn = widget.newButton({ x = 0, y = 0, onPress = function(event) print(event.time) end, })
The output is not nil.
I’m using the timer code from the Corona sample code and I want it to start counting forwards on scene entry and pause on scene exit.
the only property required to be present in every event is .name - .time is not required.
a .time is typically only present IF the dispatching for that type of event might “lag” vs system time.
fe ui events typically contain a .time value to record the exact “real time” event happened (because dispatch may lag til next frame).
but scene.hide is a “made up” (by composer/storyboard) event and doesn’t contain a .time value since dispatched immediately.
no worries, for scene.hide just read system.getTimer() - it’ll be same value (ms since launch) as if the event DID have a .time
Agreeing with @davebollinger,
System time can be gotten any where by calling: system.getTimer()
Events that have a time field are passing the system time at the time the event occurred. So manually getting it is the same.
That’s great, it works perfectly now, thanks.
Post code… you probably have a missing var somewhere.
function scene:hide( event ) print(event.time) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen end end
The output is nil.
btn = widget.newButton({ x = 0, y = 0, onPress = function(event) print(event.time) end, })
The output is not nil.
I’m using the timer code from the Corona sample code and I want it to start counting forwards on scene entry and pause on scene exit.
the only property required to be present in every event is .name - .time is not required.
a .time is typically only present IF the dispatching for that type of event might “lag” vs system time.
fe ui events typically contain a .time value to record the exact “real time” event happened (because dispatch may lag til next frame).
but scene.hide is a “made up” (by composer/storyboard) event and doesn’t contain a .time value since dispatched immediately.
no worries, for scene.hide just read system.getTimer() - it’ll be same value (ms since launch) as if the event DID have a .time
Agreeing with @davebollinger,
System time can be gotten any where by calling: system.getTimer()
Events that have a time field are passing the system time at the time the event occurred. So manually getting it is the same.
That’s great, it works perfectly now, thanks.