【发布时间】:2021-11-01 12:49:35
【问题描述】:
我正在使用的库是处理库。我目前正在制作游戏,我需要在添加后每 2 秒从列表中删除项目(项目将由 Keypressed SPACE 添加)。我试过这个:
List<String> items = new ArrayList<>();
boolean timeStarted;
int timeDuration = 2000;
int startTime = 0;
if (timeStarted) {
int currentDuration = millis() - startTime;
if (currentDuration >= timeDuration) {
items.remove(0);
startTime = millis();
timeStarted = false;
}
}
public void keyPressed(KeyEvent e) {
int keycode = e.getKeyCode();
if (keycode == 32) { // SPACE
startTime = millis();
timeStarted = true;
items.add("new item");
}
但这只会删除列表中的第一项,如果我按 SPACE 太快(同时添加太多项)会卡住。
谁能帮助我或告诉我如何处理这个问题?提前致谢!
【问题讨论】:
-
@Eritrean 感谢您的评论,但我只想通过使用处理库来完成此操作,因为我不熟悉其他人...
标签: java processing