I am trying to pause the game, when the game loses focus (onBlur), and continue everything when it regains focus (onFocus). The recommended way of Pause/Play is to set the timescale of the application to 0 or 1. So far so good, I can pause the game and all the animations. But there are several problems with this approach:
Audio that is playing in the game is not paused, so it is not depending on the time scale I guess? Ofc I can mute/pause the audiosource, which is currently playing, but that doesn’t seem right, as i might have multiple audiosources in my scene, and I would need to find them all…
setTimeout and setInterval still keep going, since they also don’t depend on the applications timescale. Therefore, if I’m trying to time anything with these (e.g. like a delayed score animation), the timings will be a complete mess.
Is there a different solution/approach for pausing and resuming the application? Are there internal alternatives for using setTimeout and setInterval, like, should i use tweens for these instead?
Why not put everything under on entity as a folder and then add the pause/stop code into the entity(folder),and go from there just a more simple method and if you dont get what I’m saying I can show you in an video
Audio is an odd one as perhaps it should be affected be timescale Not sure whether to call it a bug or a proposed feature. I personally think it should.
setTimeout and setInterval are browser functions rather than PlayCanvas API. You could write your own manager to handle similar functionality in a pc.Script or have the manager listen to the update event from the pc.app
Thanks, I didn’t know about a global update event. That is just what I need, since a small timeout/interval system shouldn’t be too hard to write myself.
About slowing down the audio, who could know about that, maybe @will?