Jump to content

Sounds in Phaser (JS vs TS)


scutajar
 Share

Recommended Posts

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

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...