kurhlaa

Prevent game stopping on tab switch

Recommended Posts

Hello,

It seems, that if I switch browser's tab while game is running - the world stops completely. If I start jumping, then switch tab and wait for some time, then switch back - I'm still in the air and continue to fall down. Bullets also freeze in the air.

I try to add this to the create() function, but there is no effect:

var game = this.sys.game;

game.events.off('hidden', game.onHidden, game);
game.events.off('visible', game.onVisible, game);

 

What can I do to prevent stopping of the physics loop? I could live with missing animations, sounds and things like that, but physics should continue to run and change bodies positions. What can I do?

Share this post


Link to post
Share on other sites

There’s nothing you can do. The browser halts Phaser, it doesn’t do it itself.

You ought to pause the game fully if they switch tab and resume when they come back. If this is an IO game and you want it to not pause then you’ll have to work out for yourself how to pause and resume in a seamless way, because the browser is going to halt phaser regardless.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.