【发布时间】:2017-06-22 09:28:02
【问题描述】:
我有一个Timer,我安排了一个TimerTask 与delay 0 和period 150。
现在我想更改period,但Timer 已经在运行。
我现在如何更改period?
private int penultimateStep = 1;
private int lastStep = 1;
private Timer move = new Timer();
private TimerTask movePlayer = new TimerTask(){
public void run(){
//Schritte ändern
if(lastStep==3){
lastStep = 2;
penultimateStep = 1;
}
else if(lastStep==1){
lastStep = 2;
penultimateStep = 3;
}
else if(lastStep==2){
if(penultimateStep==1){
lastStep = 1;
penultimateStep = 3;
}
else if(penultimateStep==3){
lastStep = 3;
penultimateStep = 1;
}
}
}
};
...
move.schedule(movePlayer, 0, 150);
【问题讨论】:
-
你能分享一些代码来帮忙吗?
-
取决于您使用的计时器。
-
您要重新安排任务吗?
-
hastebin.com/xemucaxaru.cs我想在计时器运行时将速度从150改为200(例如)