嗨,我目前正在为我的应用程序开发一个计时器,我将使用 phonegap 将其移植到 android 手机上,它是关于一个带有 10 秒计时器的球类游戏
目前我正在使用 timer++ 增量
createLevel: function(lvl) {
// create levels manually
// TODO: import from level editor
switch(lvl) {
case 1: {
timer2 = 11;
walls.create((320-128)/2, (480-32)/2, 'element-w').body.immovable = true;
break;
}
case 2: {
timer2 = 11;
walls.create code here
break;
}
case 3: {
timer2 = 11;
walls.create code here
break;
}
case 4: {
timer2 = 11;
walls.create code here
break;
}
case 5: {
timer2 = 11;
walls.create code here
break;
}
case 6:{
timer2 = 11;
walls.create code here
break;
}
case 7:{
timer2 = 11;
walls.create code here
break;
}
case 8:
{
timer2 = 11;
walls.create code here
break;
}
case 9:
{
timer2 = 11;
walls.create code here
break;
}
case 10:
{
timer2 = 11;
walls.create code here
break;
}
default: {
break;
}
}
},
updateCounter: function() {
timer++;
timer2--;
timerText.content = "Time: "+timer2;
totalTimeText.content = "Total time: "+(totalTimer+timer);
if(timer2==-1)
{
//this.game.add.text(320/3, 480/2, "GAMEOVER", { font: "36px Cambria", fill: "#ffff00" });
this.game.paused =! this.game.paused;
this.buttonContinue = this.add.button(0, 0, 'gameover', this.mainM, this);
totalTimer=0;
timer=-2;
level=1;
//this.buttonContinue = this.add.button(0, 0, 'screen-howtoplay', this.game.state.start('MainMenu');, this);
}
我使用计时器添加到总计时器和计时器2在游戏结束前将实际计时器设置为11
但是,当游戏滞后时,计时器会以难以置信的速度快速破坏我的游戏,那么我如何以这样的方式实现,即使设备滞后计时器仍能正常运行?