简体   繁体   中英

How to delay the start time of a timer in JavaScript (Phaser)

I have a JavaScript file that I am working on for a game using the Phaser Framework, and I have multiple timers, the only thing is I'm not sure how to make one of the timers start running a little bit after the first one has started. I cannot provide code that will actually work due to the framework JS file but I can provide my code that I am working with.

//This is my first timer, it works how I like
timer1 = game.time.events.loop(1500, addAnimals, this);
//I want this one to start a little bit later than the other one
timer2 = game.time.events.loop(1500, increaseScore, this);

I'm not sure how I could fix this, if anyone could assist me that would be great!

I have figured it out, I decided to run a timer that only runs once, to call a function which then runs, like this:

firstTimer= game.time.events.add(Phaser.Timer.SECOND * 3.85, firstRun, this);

And the first run function:

function firstRun() {
score += 1;
scoreLabel.text = score;
timer2 = game.time.events.loop(1500, increaseScore, this);
}

Which runs it own timer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM