Geroy290
Geroy290

Reputation: 478

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!

Upvotes: 1

Views: 4129

Answers (1)

Geroy290
Geroy290

Reputation: 478

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.

Upvotes: 4

Related Questions