How would you play a sound every certain amount of seconds in Phaser?

431 views Asked by At

I need to play a sound using Phaser Framework that plays every 10 seconds. But how can I implement a event that gets executed when the sound finished playing ? so then I can start a 10 second timer to play the sound again.

1

There are 1 answers

0
Nico On

You can use an event on the sound. E.g:

sound.onStop.add( // When it ends set a timeout function to restart it
    function() {
        setTimeout(
            function() {
                sound.play();
            },
            10000 // Delay
        )
    }
);
sound.play();

You might be able to simplify this code by using Phaser tweens, but I haven't used them much so I don't really know how.