In my application I calculate how long user played the game. When user pauses the game I stop my time-counter. I added listener for event Event.APPLICATION_SUSPEND (I also tried to use Event.APPLICATION_BACKGROUND). This listener pauses the game and stops time-counter if user pressed "Home" button. But this event is fired only when user returned to the game from the background and my timer doesn't stops correctly. How can I do something before application goes to background? Is it possible to catch "Home" button press in event Event.KEY_DOWN?
Comments
Event.APPLICATION_SUSPEND for going to background and
Event.APPLICATION_RESUME for going back
But you can't make any additional callback calls or some other non atomic (assync) functions inside SUSPEND event listener, as system only notifies the app, that it will go to background, and does not actually give time to finish the tasks.
so for example, if you put print statement inside SUSPEND event, it will only print out in the console when you get back, although it was executed before going to background
So if they are time and server based, the progress is run on the server based on time, so whenever you connect, the progress displayed depends on the time that has passed. Hope that helps your question.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
Likes: seppsepp