Java 在libgdx中,如何打印倒计时?
我希望我的游戏运行10秒打印秒数,当它达到0时,游戏结束。从现在开始,我可以从0打印到10,10秒后游戏就结束了,但我需要相反的结果Java 在libgdx中,如何打印倒计时?,java,android,timer,libgdx,countdown,Java,Android,Timer,Libgdx,Countdown,我希望我的游戏运行10秒打印秒数,当它达到0时,游戏结束。从现在开始,我可以从0打印到10,10秒后游戏就结束了,但我需要相反的结果 time+= delta; System.out.println(String.format("time: %,.2f", time)); if(!tOn) { tOn = true; Timer.schedule(new Task() { @Overr
time+= delta;
System.out.println(String.format("time: %,.2f", time));
if(!tOn) {
tOn = true;
Timer.schedule(new Task() {
@Override
public void run() {
currentState = GameState.GAMEOVER;
}
}, 10);
}
将可变时间设置为10,并将其作为时间递减-在计时器内打印
int time = 10;
System.out.println(String.format("time: %,.2f", time));
if(!tOn) {
tOn = true;
Timer.schedule(new Task() {
@Override
public void run() {
time--;
if(time == 0){
currentState = GameState.GAMEOVER;
}
}
}, 10);
}
所以让时间从10开始-=δ;