linkzao Posted December 4, 2014 Share Posted December 4, 2014 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 More sharing options...
Tuan Posted December 15, 2014 Share Posted December 15, 2014 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 More sharing options...
Ryan Posted January 17, 2015 Share Posted January 17, 2015 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 More sharing options...
horkoda Posted January 17, 2015 Share Posted January 17, 2015 I have the same issue as all of the above. EDIT: There's a report of this on github where rich said it's a browser issue, and not a Phaser issue.Any workarounds? Link to comment Share on other sites More sharing options...
rich Posted January 18, 2015 Share Posted January 18, 2015 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 More sharing options...
horkoda Posted January 18, 2015 Share Posted January 18, 2015 Does rAF affect the update() function as well? I thought it was decoupled in 2.2.x? Link to comment Share on other sites More sharing options...
rich Posted January 18, 2015 Share Posted January 18, 2015 Update and render were decoupled. But raf still controls *everything* - its the heartbeat of the browser. Shut it down and nothing updates. Link to comment Share on other sites More sharing options...
horkoda Posted January 18, 2015 Share Posted January 18, 2015 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 More sharing options...
rich Posted January 18, 2015 Share Posted January 18, 2015 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. horkoda 1 Link to comment Share on other sites More sharing options...
jdnichollsc Posted May 19, 2015 Share Posted May 19, 2015 Hi Rich, What is the config option to use setTimeout instead of raf? Thanks in advance Link to comment Share on other sites More sharing options...
theaidem Posted September 22, 2015 Share Posted September 22, 2015 Hi Rich, What is the config option to use setTimeout instead of raf? Thanks in advancevar config, game;config = { forceSetTimeOut: true, renderer: Phaser.CANVAS, width: 1000, height: 700};game = new Phaser.Game(config); jdnichollsc 1 Link to comment Share on other sites More sharing options...
jdnichollsc Posted September 22, 2015 Share Posted September 22, 2015 var config, game;config = { forceSetTimeOut: true, renderer: Phaser.CANVAS, width: 1000, height: 700};game = new Phaser.Game(config);Ohh Thanks my friend! I don't remember this hahaha Link to comment Share on other sites More sharing options...
charlieRobinson Posted November 15, 2016 Share Posted November 15, 2016 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 :'( jdnichollsc 1 Link to comment Share on other sites More sharing options...
Recommended Posts