Jump to content

Looped Timer with action every second?


quiphop
 Share

Recommended Posts

Hi everyone.

I have the looped timer :

timer = this.game.time.create(false);
timer.loop(Phaser.Timer.SECOND * 3, this.endTimer, this);
timer.start();

Everything works good, but i want to play sound every ticked second, how to implement this?
 

Link to comment
Share on other sites

Use a simple setInterval to loop your sound. It'll play every 1000ms. To stop playing the sound, use clearInterval. Note that you might have to set your looping parameter to false when you add the sound to the game.

setInterval(function(){
yourSound.play(); 
}, 1000);

 

Link to comment
Share on other sites

Thanks @DevJ, but i found better solution based on time delta (thanks to @Str1ngS);
So, At the start of game i'm create a variable of current time
 

var tick = game.time.now;

Then at the update func. i'm checking the time delta
var tick = this.game.time.now;

if (game.time.now - tick > 100) {
//...
 tick = game.time.now;
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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