Jump to content

game.stage.disableVisibilityChange not working


linkzao
 Share

Recommended Posts

Hi, I'm using game.stage.disableVisibilityChange = true; so my game doesn't stop when I alt+tab, change tab or something like that, but it's not working. Even with it set as true my game keeps stopping.

 

Here's my create() function and my game instance:

var game = new Phaser.Game(1728, 1344, Phaser.AUTO, 'game', { preload: preload, create: create, update: update, render: render });function create() {     mouseclicked = false;     var nickname = 'Hero '+ (heroes.length + 1);     socket.emit('new-player', {'nickname': nickname});     game.physics.startSystem(Phaser.Physics.ARCADE);     game.stage.disableVisibilityChange = true;     background = game.add.sprite(0, 0, 'background');     background.inputEnabled = true;     background.input.pixelPerfectClick = true; }

Thanks in advance.

Link to comment
Share on other sites

  • 2 weeks later...

Hi, I'm using game.stage.disableVisibilityChange = true; so my game doesn't stop when I alt+tab, change tab or something like that, but it's not working. Even with it set as true my game keeps stopping.

 

Here's my create() function and my game instance:

var game = new Phaser.Game(1728, 1344, Phaser.AUTO, 'game', { preload: preload, create: create, update: update, render: render });function create() {     mouseclicked = false;     var nickname = 'Hero '+ (heroes.length + 1);     socket.emit('new-player', {'nickname': nickname});     game.physics.startSystem(Phaser.Physics.ARCADE);     game.stage.disableVisibilityChange = true;     background = game.add.sprite(0, 0, 'background');     background.inputEnabled = true;     background.input.pixelPerfectClick = true; }

Thanks in advance.

I had the same problem although I set game.stage.disableVisibilityChange = true;

The game doesn't run in background when I change Browser Tab. But it can run in background if I focus on another program (like opening Notepad++ over the Browser)

Link to comment
Share on other sites

  • 1 month later...

Just wanted to say that I am having the same issue.

this.game.stage.disableVisibilityChange = true;

In my Boot.js file. The game pauses when I open a new tab in the same window, but does not pause when I focus on another application. This happens in both Firefox and Chrome.

Link to comment
Share on other sites

There's not much you can do about this I'm afraid. The boolean controls if Phaser will still update when the browser fires a visibility change (i.e. giving focus to another app), but what happens when you change tab is different, it's the browser deciding to no longer fire requestAnimationFrame events, consequently pausing your game (even though Phaser itself never thinks it has paused, it just never gets its core loop called because rAf has been halted).

 

Not all browsers do this (although most do now it appears), and it sort of makes sense - it's just a waste of CPU / battery to keep stuff constantly running in a tab you can't even see. Even so, it's frustrating to not have any kind of say in it.

Link to comment
Share on other sites

What is the reason behind not using setTimeout/setInterval for logic updates?

Raf seems to be more suited for rendering. Also setTimeout/setInterval is not being paused (although they might be rounded) when the tab is inactive, while raf is (source).

 

I see Phaser is not the only one using raf as their main loop. How so?

Link to comment
Share on other sites

Phaser has a config option to force it to use setTimeout instead of raf, even when raf is available. Use it if you want, but there's no way it will ever be the default. The precision of timing it offers is horrendous (which is why no one else uses it either). You could use it as a back-up for when raf is paused I guess, but this is an extreme edge case, so not something we'll support as a 'feature'.

 

I'm not convinced it's a 100% safe bet either. I think if a browser wants to suspend what's happening in a busy but hidden tab, then it will do so regardless of how the event fired.

Link to comment
Share on other sites

  • 4 months later...
  • 4 months later...
  • 1 year later...

I had same issue of game not running while not in focus so I added that code: game.stage.disableVisibilityChange = true; and it fixed it!

I had some different issues and had to revert back to an earlier save and, somehow, game.stage.disableVisibilityChange = true; no longer works!

The code is exactly the same and nothing else changed that would have affected it?! HOW!? WHY!? I need my game to run to in the back ground :'(

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...