Jump to content

Sounds in Phaser (JS vs TS)


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

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.

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.


  • Recently Browsing   0 members

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