[英]How to delay the start time of a timer in JavaScript (Phaser)
我有一個使用Phaser Framework進行游戲的JavaScript文件,並且有多個計時器,唯一的問題是我不確定如何使其中一個計時器在第一個計時器啟動后開始運行開始。 由於框架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);
我不確定如何解決此問題,如果有人可以幫助我,那就太好了!
我已經弄清楚了,我決定運行只運行一次的計時器,以調用隨后運行的函數,如下所示:
firstTimer= game.time.events.add(Phaser.Timer.SECOND * 3.85, firstRun, this);
和第一個運行功能:
function firstRun() {
score += 1;
scoreLabel.text = score;
timer2 = game.time.events.loop(1500, increaseScore, this);
}
哪個運行它自己的計時器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.