Using PlayCanvas outside of PlayCanvas

How can I allow the players of a game to leave their browser (i.e. they are in another tab) but the game is continuously running? I am STILL making my multiplayer game (its going very well) but this is one of the three key points I need to fix. After these issues are fixed the game will be more than halfway done!

Thanks,
Chhes :cheese:

1 Like

If the game logic is running on a server, it can continue independent of whether the player switches tabs or closes the browser.

2 Likes

A JavaScript Worker still fires setInterval even tho you left the tab or minimized the browser (at least I just tested that with Chrome), which you probably need to send/receive updates from every client to calculate e.g. their ping on the server.

Two simple files to test it out:

File: test.html:

<script>
  worker = new Worker('worker.js');
</script>

File: worker.js:

var start = Date.now();

console.log("Worker start", start);

setInterval(()=>{
  var end = Date.now();
  var diff = end - start;
  if (diff > 120) {
    console.log('diff', diff);
  }
  start = Date.now();
}, 100);

The worker barely not reaches the setInterval timeout, but sometimes it goes over some milliseconds:

image

And here I just pasted the JavaScript code into DevTools, to run it into a normal environment:

image

The times go crazy and way over 100ms e.g.

What part of your game requires this, gameloop and networking?

2 Likes

What’s the name of the game

I will showcase when I am done

pretty much the entire gameplay