Is it possible to keep my game/application keep on running in background even when the user switches tabs
Normally the PlayCanvas render loop and script update methods will stop running when the browser tab is not active. That is the default browser behavior.
You can bypass that for some parts of your code by using a
setInterval() timer to execute your own code in intervals, but that isn’t guaranteed to execute in the specified frequency.
When the tab isn’t active the browser can and will throttle both
setInterval callbacks, to improve power efficiency. So the sort answer is no, but can you share some info on what you are trying to do?
Usually the recommended approach, especially with multiplayer games, is to sync the state of the game so the player doesn’t miss anything while his tab wasn’t active.
I am working on a third person game and that will be integrated to a bigger part of the website so what I need is to run it in background, will that be possible using setInterval().
Partially it’s possible but check my answer above, potentially the browser will throttle the code and run it less frequently or even pause fully.
Okay I shall try it
Also now as we know playcanvas stops all animations in background. My whole script works on the base of my api and the response that comes from that API, but now i face a major problem.
Let’s say now, I get a response==true from my api, but at this point user has minimized/switched tabs/just loading the game. At these time I already have a true from my api and animation triggers when the screen loads again or when person comes back to the tab.
Now what I want is that, if the person comes in at a particular time then it should load in the place where it is supposed to , for example if I have got a response from the api prior to user coming only then I wish to show the card already placed in its respective box and not show the animation.
For this I thought I can use states like in react, so I wanted to know if there is any method to do this in playcanvas where I can manage the game as if it is running in background and load it in the same status when the user comes in
Please do not ping users that are not currently involved in the thread.
Okay , sorry for the inconvenience