Jump to content

Any solutions when switching to tabs?


Overflowz
 Share

Recommended Posts

Hi to everyone. I have a problem regardless of tab switching or minimizing window. I understand that browsers limit or stop some JavaScript functions (e.g requestAnimationFrame/setInterval) to save power, but the game I'm doing right now is based on a live online game. If any of you had similar problem, can you please give me the solution how to do that?

 

my game mainly does Tween animations. Before doing any tween animations, save tween objects into global namespace and of course onCompleted remove it after.

If I catch game pause event, I would somehow emulate Tween's last animation (I mean the position where Sprite should be, stop that animation and move to next one) so it would do everything statically instead of rendering frames, but even so, I don't know how to do this.

 

Any thoughts?

Regards.

Link to comment
Share on other sites

From my point of view you shouldn't have to handle a pause yourself. Phaser should know the game is paused and thus adapt the tweens (or at least stop the timers so that tweens timers won't continue during a pause). Do you have any code example (or a sandbox) so we could work on this?

Link to comment
Share on other sites

Hi, sorry for long delay.

rgk

I'm already using that method, it makes canvas continue playing IF you lose focus on it. as for a tab switch or minimizing window, that does not help at all.

Skeptron

I think I was not clear. I don't really want to pause the process. While animation is playing (e.g tween) and I switch tab, it just pauses animation. When I get back to window, it continues from that state, when I switched tab. Simply to say, it just pauses animation and then continues when getting tab back.

 

My problem is that, I want that animation still played in background, because when user gets back, he should see the result what was done.

For example:

User1 does "action1", "action2" and so on.

User2 should see the animations done by User1 (server sends him what was done).

Assume User2 have tab switched. If he gets back to the game, animations will just continue playing one by one till the end, which in this case is a problem. User2 MUST see the animations done already, because he'll have time to answer to "actionN" which was done by User1 and if animations keep playing a lot, then User2 will have to wait till animations will end, so this is a problem now.

 

Any thoughts? 

Link to comment
Share on other sites

Okay, closer what I could achieve is that, to set "setForceTimeOut" to true, but still, this is limited by newer browsers with ~1000ms interval while inactive.

var Game = new Phaser.Game(..);Game.config.setForceTimeOut = true;

now I'd like to know, when and where should I switch back to rAF and vice-versa and how to use delta timers on tweens so they'll animate properly?

 

Regards.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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