AB95

Animation not pause when pause() function is triggered using $(window).blur();

Recommended Posts

Hi everyone,

i was trying to pause a scene when the browser window is not active(eg. user switches tab, ctrl/cmd+tab, another window is currently focus,etc).

 To pause the scene, i need the background music and all animations to be paused, below playground example shows my approach:

http://babylonjs-playground.com/#1MZCTQ

I got two results:

1. when I click on another window(for example a notepad) that overlapped the browser, the notepad is now focus and the browser is blur, hence both sound and animation are paused, this is expected;

2. when I ctrl/cmd+tab or manually click on another tab to switch tab, only sound is paused but the animation continues playing.

looks like $(window).blur(function() {...}); is triggered, but only bgm.pause() work, anim.pause() doesn't work.

$(window).focus(function() {
  anim.restart();
  bgm.play();
});
$(window).blur(function() {
  anim.pause();
  bgm.pause();
});

any help will be appreciated, thank you!

 

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.