Jump to content

questions about playing sound

Jes Lee

Recommended Posts

Hello, I made a slot machine to practice phaser 3.

you can test it at https://emalron.github.io/slot

the problem: the coin sound played once even if 2 or more lines are matched.

What I want was repeating playing coin sounds as much as lines were made.

function reward(matched) {
    const scene = game.scene.scenes[0];
    matched.forEach((m, i) => {
        if(m == true) {
            // play sound

            // draw line
            drawlines(scene, i);

the parameter matched is the array of matched line. if second and third line was matched, it would be [,true,true,,,,,]

so I travered through the parameter and check if the value is true then play the coin sound and draw line.

the thing is the method play() is run asynchronously. so the playing is quit when the loop found the next true value to play its own coin sound.


how can I let the loop run after the playing sound is done?

thanks for your time to read this topic.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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