megan Posted August 14, 2014 Share Posted August 14, 2014 I have a timer that creates stars every 800 ms.timer = game.time.events.loop(800, spawn_stars, true);It works great, but when the window loses focus the timers keep going. When focus is restored, all the stars that were spawned while the window was unfocused all show up at the same time (so there could be 100+ stars showing up at once, which isn't ideal for this game). This happens whether game.stage.disableVisibilityChangeis set to true or false. The timers stop properly when I use the game.paused function. Is this a bug, or is there something I'm not doing correctly? Link to comment Share on other sites More sharing options...
bryanbibat Posted August 15, 2014 Share Posted August 15, 2014 It should work, see http://examples.phaser.io/_site/view_full.html?d=time&f=basic+looped+event.js&t=basic%20looped%20event The only thing that I could see different from your code is that you used "true" instead of "this" in the third parameter for loop(). Tried it with the example above and the timer still stopped. Link to comment Share on other sites More sharing options...
megan Posted August 15, 2014 Author Share Posted August 15, 2014 I tried switching the "true" to "this" in the loop, and it still didn't work for me.However, I've been able to narrow down the problem. It seems to work fine in any situation, except for when game.stage.disableVisibilityChange = trueand then I switch to a new tab in my browser. Maybe it's because the game is still "playing", but it can't draw anything to the screen until it's visible again? Link to comment Share on other sites More sharing options...
Orbital Game Studios Posted August 26, 2014 Share Posted August 26, 2014 I'm having this exact same issue. I have a pause function built and it works perfectly well except that a couple of timers will resume when the window is resized or loses focus. I've also found the issue on my mobile phone if I pause the game, return to the home screen, then back to the app, the timers have now resumed. I haven't tried checking it's behavior with game.stage.disableVisibilitityChange = true or dug into the Phaser code itself to see where the problem lies but I have a feeling there is an odd check happening somewhere. In the mean time I will probably revert the code to not using a timer object but instead checking against an internally tracked time elapsed value which I have complete control over. Link to comment Share on other sites More sharing options...
hellovoid Posted September 29, 2014 Share Posted September 29, 2014 You should use;var nextSpawnStar = 0;spawnStarLoop: function () { // spawn star every 800 ms nextSpawnStar += this.game.time.elapsed; if(nextSpawnStar >= Phaser.Timer.SECOND * 0.8) { nextSpawnStar -= Phaser.Timer.SECOND * 0.8; this.spawnStar(); } }, Link to comment Share on other sites More sharing options...
Recommended Posts