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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.