Jump to content
GreenSock

BCI

Play sound clip in tweens

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Using SoundManager2 library, my sound has already been created. I want to call the play function once my timeline reaches the correct point. Any ideas how I can do this? Thanks in advance.


tl.set("#mod5", {visibility:"visible"}, "#mod5")
  // call soundManager --> soundManager.play('mod5')
  .staggerFrom("#e5", 0.5, {autoAlpha:0, x:180})
  .to("#e6", 0.5, {delay:1});

 

Link to comment
Share on other sites

Hi Nick and welcome to the Greensock forums.

 

You can use the call() method, which calls for a specific function at a given time, like this:

tl.set("#mod5", {visibility:"visible"}, "#mod5")
  .call(playSound)
  .staggerFrom("#e5", 0.5, {autoAlpha:0, x:180})
  .to("#e6", 0.5, {delay:1});

function playSound()
{
  soundManager.play('mod5');
}

Rodrigo.

  • Like 3
Link to comment
Share on other sites

Thanks a bunch for the reply and the warm welcome. Very excited to be using GSAP!

  • Like 1
Link to comment
Share on other sites

Also, if you're just calling a single function at that time, you could use call like this without having to create an extra playSound function:

.call(soundManager.play, ['mod5'], soundManager);
// essentially says - call play('mod5') on the soundManager object

You need to add soundManager as the 3rd parameter (scope) since soundManager.play doesn't maintain that scope automatically. Javascript can be weird ;) 

  • Like 1
Link to comment
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.
×