Inactive tab with cocos app

Hi all!
I have a timer in the game, now it is responsible for after what time the player will get +1 life.
The problem is that when the user switches the input with the game, the timer doesn’t work.
How can I track the timer?

Switches the input ? Switch tab in the web browser ?
If you want to track real time, it’s better to use Performance.now(), instead of relying on delta time cumulation

Hi! Yes I was talking about browser tab switch
When user switch browser tab I can see something like Game.EVENT_HIDE is emited (correct me if I’m wrong)
How can I implement my game timer correctly if it’s won’t tick if tab is switched?

Yes, the event HIDE and SHOW will be invoked during tab switch

We shouldn’t rely on background tick invocation, I suggest you can do some catchup logic based on time past during the tab switch.

1 Like

Hi,

It’s the browser that deactivates the inactive tags. So, you can’t do much in Cocos rather than changing your logic.

For example:
On HIDE event: save the time; says lastActiveTime
On SHOW event: calculate the duration the Player was away for. ( now - lastActiveTime) Then you can do catchup.

On a side note, it’s dangerous to use the timer on the Client side for rewarding. Eg; they can easily change date/time to steal life.

1 Like