大家好,我正在开发一款游戏,我希望它在随机的时间内向我展示一些精灵,所以我这样做了:
for (int i = 0; i < 30; i++) {
final int min = 5000;
final int max = 25000;
Random r = new Random();
int i1 = r.nextInt(max - min + 1) + min;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
//MyCODE
}
}, i1);}
}
但问题是,当我使用 postDelayed 时,它已经定义了从现在开始的 i1 时间的 30 倍,然后它会一起显示精灵。
我想做的是:
i1 = New random number between 5000-25000 -> first = run //MyCODE after "i1" seconds -> i1 = New random number between 5000-25000 -> second = run //MyCODE after "i1" seconds since "first" ........