CaptKiwi Posted October 13, 2013 Share Posted October 13, 2013 Hi Guys, I have a game that is sending out sprites to the canvas at certain time delays. If I click on another tab in the browser for a minute or so and come back to the game, then all the spites come on the screen at the same time. For example, if there was a new sprite every four seconds, once I comeback to the canvas, after a minute there would be 15 sprites all at once entering the screen. Is there a way to pause the game if the player clicks out of the canvas or out of the web browser tab? Cheers! Link to comment Share on other sites More sharing options...
rich Posted October 13, 2013 Share Posted October 13, 2013 By default the game should pause when you just click out of it, unless you've turned this off? Also it depends how you were timing the release of new sprites - what code did you use for the timer? Link to comment Share on other sites More sharing options...
CaptKiwi Posted October 13, 2013 Author Share Posted October 13, 2013 By default the game should pause when you just click out of it, unless you've turned this off? Also it depends how you were timing the release of new sprites - what code did you use for the timer? Thanks rich, I'm using the following : enemyTimer = setInterval(function() {addEnemy()}, 4000); The game action does pause, but I guess my timers are still running and hit all at once when I click back in the canvas. Link to comment Share on other sites More sharing options...
rich Posted October 13, 2013 Share Posted October 13, 2013 Yes setInterval will run regardless of browser focus / pause state. There are a couple of ways to do this, here's one:var nextSprite = 0;// then in your UPDATE function, do this:if (game.time.now > nextSprite) { // release sprite here nextSprite = game.time.now + 4000;} AhmedElyamani 1 Link to comment Share on other sites More sharing options...
CaptKiwi Posted October 13, 2013 Author Share Posted October 13, 2013 Worked perfectly, thanks rich! Link to comment Share on other sites More sharing options...
Mike Posted October 13, 2013 Share Posted October 13, 2013 By default the game should pause when you just click out of it, unless you've turned this off? I was searching for this option but couldn't find it ? I want this behaviour cause I want a running game and open chrome/firebug console to type in Please share the setting... I thought also that there was such a topic but couldn't find it in the forum. Link to comment Share on other sites More sharing options...
rich Posted October 13, 2013 Share Posted October 13, 2013 game.stage.disableVisibilityChange = true; Mike 1 Link to comment Share on other sites More sharing options...
Recommended Posts