Jump to content

Repeat timer event at random time


kvazmatik
 Share

Recommended Posts

Hello guys,

I'm trying make timed event which will run in loop at random intervals. So I took some code from labs and modified it.

function create ()
{
    timedEvent = this.time.addEvent({ delay: 1000, callback: onEvent, callbackScope: this});
}

function onEvent ()
{
    timedEvent.reset({ delay: Phaser.Math.Between(100,5000), callback: onEvent, callbackScope: this, repeat: 1});
}

This seems to work but I'm little bit confused why there needs to be

repeat: 1,

argument. Or it's just fine as it is. 

Link to comment
Share on other sites

  • 6 months later...

Thanks for the help! I learned how to make timed events.

You can include repeat like this btw - 

timedEvent = this.time.addEvent({ delay: 1000, callback: onEvent, callbackScope: this, repeat: 1});

 

For some reason, repeat: 1 repeats the events 2 times. repeat: 0 repeats it one time.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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