Sign in to follow this  
locomotive

looped timed event with random delay

Recommended Posts

Hello ,

i am new to building games , started my phaser3 journey one week ago ,

i am trying to make a looped timed event run multiple times , each time a different delay ,

so for example  instead of making  the event run every 5 sec as this line of code does :

phonecall = this.time.addEvent({ delay: 5000,  loop: true, callback: onEvent, callbackScope: this });

i need it to run at random intervals from 5 to 30 secs ( ex : first time 5 sec second time 10 sec third time 7 sec) any value between the interval i set  , i tried to do this :

    	phonecall = this.time.addEvent({ delay: Phaser.Math.Between(5000,30000),  loop: true, callback: onEvent, callbackScope: this });

but it seems that its not working ..

sorry for my bad use of English  , 

thanks

Share this post


Link to post
Share on other sites

Hi,

You add the event once with the evaluated value of "Phaser.Math.Between". Once created, the looped event will not change, its delay stay the same.

I think you could add a simple event that adds itself on callback, with a new delay, by providing the appropriate context.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.