I have a function inside scheduler that calls the function after every 19 seconds and the functions sends data to the backend.
whenever i switch the screen or minimize the browser game tab, The scheduler pauses which i want to avoid as the delay for which the scheduler does’nt sends the data gets very big as browser window is minimized or tab is switched and scheduler is paused.
Is there any way i can avoid scheduler from getting paused ?
Or Can setInterval provide the desired result ?
Thanks in advance.
I have the same problem.
I try to use update() to fix this issue.
For a count down timer, thie issue can be resolved.
However, when applied to a tween, the same problem still occurs.
Does anyone have a better solution?
Hey @dukeofchiwawa, just jumping in since I’m facing the same problem.
Yeah, this happens because browsers pause or slow down timers and animations when you switch tabs or minimize the window. So things like scheduler, update(), and even tweens won’t run properly in the background.
Your workaround using Date.now() in update() works well for countdowns since it uses real time instead of frame time. But like you said, it doesn’t help much with tweens or anything tied to the frame rate.
If you’re just trying to run something like a backend sync every few seconds, you could try using setInterval. It still gets throttled when the tab is inactive, but it usually runs better than Cocos’s scheduler in those cases.
Another trick is to detect when the tab becomes active again and then handle anything that got missed while it was inactive.
Hope that helps a bit! Would love to hear if someone finds a better solution too.