scutajar Posted September 24, 2013 Share Posted September 24, 2013 This is a quick question regarding the way sounds are handled in the current JavaScript version, as opposed to the old TypeScript version.Before, I used to add my audio files to the loader, and then just call play through the game's SoundManager. This let me play two opposing sounds after each other, stopping the first one and immediately playing the second one, which is what I want.With the current JavaScript version, I have to add two audio files as variables, and then play them whenever necessary (ie: I don't actively have to touch the SoundManager). However, now when I play two sounds after each other, the second one doesn't always play.What would I have to do to bring the previous functionality back? Link to comment Share on other sites More sharing options...
rich Posted September 24, 2013 Share Posted September 24, 2013 Got an example somewhere? I'm playing 10 sounds at once in a game I'm working on at the moment and it's ok (using Web Audio only of course). Link to comment Share on other sites More sharing options...
scutajar Posted September 24, 2013 Author Share Posted September 24, 2013 Well, I first declare these in my create function:goodSound = myGame.add.audio("good");badSound = myGame.add.audio("bad");And then on collision between two sprites, I have this following code:if (letterType === "vowel") { score += 100; scoreText.setText("Score: " + score.toString()); goodSound.play();} else { badSound.play();}It does work, except when I start manually dragging stuff really quickly, then some of the sounds aren't played. I'll try put up a playable example. Link to comment Share on other sites More sharing options...
rich Posted September 24, 2013 Share Posted September 24, 2013 Do you want it so that good OR bad are playing, but never at the same time? I.e. they will never overlap, one will cut the other off? Link to comment Share on other sites More sharing options...
scutajar Posted September 24, 2013 Author Share Posted September 24, 2013 That's it, one should cut the other off. As it stands, the first sound keeps playing, and the second sound never plays. (Strangely enough, after this happens, if I keep dragging, nothing plays, and I have to wait a while before I can hear sound again.) Link to comment Share on other sites More sharing options...
rich Posted September 24, 2013 Share Posted September 24, 2013 A much easier way would be to combine the 2 sounds in one file (with a gap between them) and use Sound.addMarker. Then you can just have 1 sound object and do sound.play('good') or sound.play('bad') and it will jump to that point in the sound. Link to comment Share on other sites More sharing options...
scutajar Posted September 24, 2013 Author Share Posted September 24, 2013 Actually, I just tested it again, and the only time this is happening is when the sound is the same, ie: the game plays goodSound, and must play goodSound again. I'm assuming the sound isn't played because it technically is already playing, but is there any way to force it to play the same sound again? Link to comment Share on other sites More sharing options...
rich Posted September 24, 2013 Share Posted September 24, 2013 Yes, the last parameter of play:play: function (marker, position, volume, loop, forceRestart) Link to comment Share on other sites More sharing options...
rich Posted September 24, 2013 Share Posted September 24, 2013 Or if you KNOW for sure that the sound is already playing you can use Sound.restart Link to comment Share on other sites More sharing options...
scutajar Posted September 24, 2013 Author Share Posted September 24, 2013 Awesome, I must have missed that, thanks so much! Link to comment Share on other sites More sharing options...
rich Posted September 24, 2013 Share Posted September 24, 2013 It's easily missed without docs. On the plus side they're nearly finished scutajar 1 Link to comment Share on other sites More sharing options...
Recommended Posts