Sign in to follow this  
quiphop

Looped Timer with action every second?

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?
 

Share this post


Link to post
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);

 

Share this post


Link to post
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;
}

 

Share this post


Link to post
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.

Guest
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.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.