Stop playing sound before going on to next function

Viewed 37

I was tasked to create a simple mini game based solely on Javascript. I encountered a problem as I was adding in sound effects..

After the player drowns, the game should 'return' to its initial frame with one 'live' count decreased. During the drowning action, it plummets down the lake while the sound effect comes into place. However, the sound is activated a few .seconds late and the player freezes at the bottom of the lake. The game does not return either.

I have also tried adding stop() but it doesn't work. Here's a fragment of the relevant code.

gameCharacter_y +=2;
drownSound.play();
    
    
return;

Been stuck for days now and am an absolute beginner, would appreciate and be grateful for any suggestions! Thanks.

1 Answers

In order to manipulate sound you should have a soundmanager... This makes it really easy to see what clips are playing and pause them and do with them as you please! I'm not sure how to make one in JavaScript... But what you are looking for is...

drownSound.pause();

There is no 'stop()' method apparently...

Related