简体   繁体   English

如何在JavaScript(Phaser)中延迟计时器的开始时间

[英]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. 我有一个使用Phaser Framework进行游戏的JavaScript文件,并且有多个计时器,唯一的问题是我不确定如何使其中一个计时器在第一个计时器启动后开始运行开始。 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. 由于框架JS文件,我无法提供可以实际使用的代码,但是我可以提供正在使用的代码。

//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. 哪个运行它自己的计时器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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